ref: 75145b53a7b58235f199f526df415e1be0416a99
parent: 8374ab85855ce9371f62861f5d2fb518eef9defa
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Sun Oct 15 12:18:14 EDT 2023
New Class and Instance
--- a/src/MicroHs/Expr.hs
+++ b/src/MicroHs/Expr.hs
@@ -63,8 +63,8 @@
| Import ImportSpec
| ForImp String Ident EType
| Infix Fixity [Ident]
- | Class (Maybe EConstraint) LHS [EBind] -- XXX will probable need initial forall with FD
- | Instance [IdKind] (Maybe EConstraint) EConstraint [EBind] -- no deriving yet
+ | Class [EConstraint] LHS [EBind] -- XXX will probable need initial forall with FD
+ | Instance [IdKind] [EConstraint] EConstraint [EBind] -- no deriving yet
--Xderiving (Show, Eq)
data ImportSpec = ImportSpec Bool Ident (Maybe Ident) (Maybe (Bool, [ImportItem])) -- first Bool indicates 'qualified', second 'hiding'
@@ -381,8 +381,8 @@
where f AssocLeft = "l"; f AssocRight = "r"; f AssocNone = ""
Class sup lhs bs -> "class " ++ ctx sup ++ showLHS lhs ++ showWhere bs
Instance vs ct ty bs -> "instance " ++ showForall vs ++ ctx ct ++ showEType ty ++ showWhere bs
- where ctx Nothing = ""
- ctx (Just t) = showEType t ++ " => "
+ where ctx [] = ""
+ ctx ts = showEType (ETuple ts) ++ " => "
showConstr :: Constr -> String
showConstr (Constr i ts) = unwords (showIdent i : map showEType ts)
--- a/src/MicroHs/Parse.hs
+++ b/src/MicroHs/Parse.hs
@@ -264,7 +264,8 @@
dig (TInt _ i) | -2 <= i && i <= 9 = Just i
dig _ = Nothing
pPrec = satisfyM "digit" dig
- pContext = optional (pTypeApp <* pSymbol "=>")
+ pContext = (pCtx <* pSymbol "=>") <|< P.pure []
+ pCtx = pParens (emany pType) <|< ((:[]) <$> pTypeApp)
pLHS :: P LHS
pLHS = (,) <$> pUIdentSym <*> emany pIdKind
--
⑨