Type constructors work in typeclass instances

This commit is contained in:
Dustin Swan 2026-03-26 21:47:51 -06:00
parent 82816e7fad
commit 0514889ba6
No known key found for this signature in database
GPG key ID: 30D46587E2100467
2 changed files with 10 additions and 0 deletions

View file

@ -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]

View file

@ -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);
}
} }
} }
} }