Type constructors work in typeclass instances
This commit is contained in:
parent
82816e7fad
commit
0514889ba6
2 changed files with 10 additions and 0 deletions
|
|
@ -19,10 +19,15 @@ String : Eq;
|
||||||
|
|
||||||
Semigroup a { cat : a \ a \ a };
|
Semigroup a { cat : a \ a \ a };
|
||||||
String : Semigroup;
|
String : Semigroup;
|
||||||
|
List : Semigroup;
|
||||||
|
|
||||||
Maybe a = None | Some a;
|
Maybe a = None | Some a;
|
||||||
Bool = True | False;
|
Bool = True | False;
|
||||||
|
|
||||||
|
# myTest = cat 3 4;
|
||||||
|
# myTest2 = cat [3, 4] [4, 5];
|
||||||
|
# myTest3 = debug! "myTest2" myTest2;
|
||||||
|
|
||||||
# nth : Int \ List a \ Maybe a
|
# nth : Int \ List a \ Maybe a
|
||||||
# in host at the moment, until we get typeclasses or something and this can work on strings too
|
# in host at the moment, until we get typeclasses or something and this can work on strings too
|
||||||
# nth = i list \ [i, list]
|
# nth = i list \ [i, list]
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,11 @@ function infer(expr: AST, env: TypeEnv, subst: Subst): TypeAST | null {
|
||||||
if (!instances || !instances.has(resolved.name)) {
|
if (!instances || !instances.has(resolved.name)) {
|
||||||
warn(`No instance ${constraint.className} ${resolved.name}`, expr);
|
warn(`No instance ${constraint.className} ${resolved.name}`, expr);
|
||||||
}
|
}
|
||||||
|
} else if (resolved.kind === 'type-apply' && resolved.constructor.kind === 'type-name') {
|
||||||
|
const instances = moduleInstances.get(constraint.className);
|
||||||
|
if (!instances || !instances.has(resolved.constructor.name)) {
|
||||||
|
warn(`No instance ${constraint.className} ${resolved.constructor.name}`, expr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue