Replies: 3 comments
-
so if I understand correctly you would like to define a function type SortType ~ (A: Type) {
int ~ (A = Int)
str ~ (A = String)
} you can think of those elements as evidence of membership in the subset your defined. if you have that then you can define your sorting function like this List.sort<A: Type>(Ev: SortType(A), xs: List<A>): List<A>
case Ev {
int: ?radix_sort
str: ?generic_sort
} doing case analysis on the evidence. and you can call it like this xs = [+1, -2, +3]
ys = ["a", "aa", "aaa"]
List.sort!!(xs)
List.sort!!(ys) because kind should be able to fill those holes. however trying this zs = [1, 2, 3] :: List<Nat>
List.sort!!(zs) shouldn't ever typecheck because there's no evidence for as of kind 1.0.32 the typechecker isn't filling those holes correctly, that's a bug and will be fixed. |
Beta Was this translation helpful? Give feedback.
-
Thanks for a detailed answer! I think this principle is acceptable (at least for now). Should the need for "compile time specialization" become stronger (e.g. with the advent of optimization phase of the Kind compiler development), this might be reconsidered (from syntactic sugar to the compiler giving some advices to users based on frequent patterns). Shall we leave this open and tag it as something related e.g. to optimization? |
Beta Was this translation helpful? Give feedback.
-
Kind doesn't actually create new constructors when filling holes. That'd step on the realms of unification, which we avoid to keep the type-checker simpler and faster. Perhaps in a future? |
Beta Was this translation helpful? Give feedback.
-
Can I somehow express in Kind, that applying
sort()
on a list of strings shall use a generic sorting algorithm, but applying the samesort()
function to a list of integers shall use e.g. radix sort?Beta Was this translation helpful? Give feedback.
All reactions