From 0514889ba6517f686fb305ac09e0924ffab8306d Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Thu, 26 Mar 2026 21:47:51 -0600 Subject: [PATCH] Type constructors work in typeclass instances --- src/cg/01-stdlib.cg | 5 +++++ src/typechecker.ts | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/cg/01-stdlib.cg b/src/cg/01-stdlib.cg index 8852925..d712704 100644 --- a/src/cg/01-stdlib.cg +++ b/src/cg/01-stdlib.cg @@ -19,10 +19,15 @@ String : Eq; Semigroup a { cat : a \ a \ a }; String : Semigroup; +List : Semigroup; Maybe a = None | Some a; Bool = True | False; +# myTest = cat 3 4; +# myTest2 = cat [3, 4] [4, 5]; +# myTest3 = debug! "myTest2" myTest2; + # nth : Int \ List a \ Maybe a # in host at the moment, until we get typeclasses or something and this can work on strings too # nth = i list \ [i, list] diff --git a/src/typechecker.ts b/src/typechecker.ts index b1c8994..374538d 100644 --- a/src/typechecker.ts +++ b/src/typechecker.ts @@ -168,6 +168,11 @@ function infer(expr: AST, env: TypeEnv, subst: Subst): TypeAST | null { if (!instances || !instances.has(resolved.name)) { 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); + } } } }