Skip to content

Commit

Permalink
Implement InstanceSigs
Browse files Browse the repository at this point in the history
  • Loading branch information
augustss committed Feb 5, 2025
1 parent 2155bb1 commit 15e22dc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Differences:
* ImportShadowing
* ImportQualifiedPost
* IncoherentInstances
* InstanceSigs
* KindSignatures
* LambdaCase
* MonoLocalBinds
Expand Down
2 changes: 1 addition & 1 deletion src/MicroHs/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ pClsBind =
pInstBind :: P EBind
pInstBind =
uncurry Fcn <$> pEqns
-- no InstanceSig yet <|< Sign <$> (pLIdentSym <* dcolon) <*> pType
<|< Sign <$> ((esepBy1 pLIdentSym (pSpec ',')) <* dcolon) <*> pType

-------------

Expand Down
7 changes: 5 additions & 2 deletions src/MicroHs/TypeCheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,13 +1309,16 @@ expandInst dinst@(Instance act ib) = do
InstanceBody bs -> do
-- XXX this ignores type signatures and other bindings
-- XXX should tack on signatures with ESign
let clsMdl = qualOf qiCls -- get class's module name
ies = [(i, ELam loc qs) | Fcn i qs <- bs]
let signs = [ (i, t) | Sign is t <- bs, i <- is ]
addSign i e = maybe e (ESign e) $ lookup i signs
clsMdl = qualOf qiCls -- get class's module name
ies = [(i, addSign i $ ELam loc qs) | Fcn i qs <- bs]
meth i = fromMaybe (ELam loc $ simpleEqn $ EVar $ setSLocIdent loc $ mkDefaultMethodId $ qualIdent clsMdl i) $ lookup i ies
meths = map meth mis
sups = map (const (EVar $ mkIdentSLoc loc dictPrefixDollar)) supers
args = sups ++ meths
instBind (Fcn i _) = i `elem` mis
instBind (Sign is _) = all (`elem` mis) is
instBind _ = False
case filter (not . instBind) bs of
[] -> return ()
Expand Down

0 comments on commit 15e22dc

Please sign in to comment.