Skip to content

Commit

Permalink
fix type alias and add typecast support to haskell
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-berbel committed May 2, 2018
1 parent a3c95c6 commit 53d9dc9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions spec/HaskellSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ spec = do

it "parses inline type annotations" $ do
hs "x = 1 :: Int" `shouldBe` Variable "x" (TypeCast (MuNumber 1) (SimpleType "Int" []))

it "parses inline type annotations with restrictions" $ do
hs "x = 1 :: (Num a, Foldable t) => t a" `shouldBe` Variable "x" (TypeCast (MuNumber 1) (SimpleType "t a" ["Num a", "Foldable t"]))
3 changes: 2 additions & 1 deletion src/Language/Mulang/Parsers/Haskell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mu (HsModule _ _ _ _ decls) = compact (concatMap muDecls decls)
where
mergeDecls decls exp = compact (decls ++ [exp])

muDecls (HsTypeDecl _ name _ t) = [TypeAlias (muName name) (muTypeId t)]
muDecls (HsTypeDecl _ name args t) = [TypeAlias (unwords . map muName $ name : args) (muTypeId t)]
muDecls (HsDataDecl _ _ name _ _ _ ) = [Record (muName name)]
muDecls (HsTypeSig _ names (HsQualType constraints t))
= map (muTypeSignature constraints t) names
Expand Down Expand Up @@ -90,6 +90,7 @@ mu (HsModule _ _ _ _ decls) = compact (concatMap muDecls decls)
muExp (HsEnumFromThenTo from thn to) = Application (Reference "enumFromThenTo") [(muExp from), (muExp thn), (muExp to)]
muExp (HsListComp exp stmts) = For (map muStmt stmts) (Yield (muExp exp))
muExp (HsDo stmts) | (HsQualifier exp) <- last stmts = For (map muStmt stmts) (Yield (muExp exp))
muExp (HsExpTypeSig _ exp (HsQualType cs t)) = TypeCast (muExp exp) (muType t cs)
muExp e = debug e

muLit (HsCharPrim v) = MuString [v]
Expand Down

0 comments on commit 53d9dc9

Please sign in to comment.