@@ -9,22 +9,28 @@ import qualified AST.Type as T
9import qualified AST.Variable as Var
9import qualified AST.Variable as Var
10import Parse.Helpers
10import Parse.Helpers
12tvar :: IParser T.RawType
13tvar :: IParser T.RawType
13−tvar = T.Var <$> lowVar <?> "type variable"
15+ T.Var <$> lowVar <?> "type variable"
16tuple :: IParser T.RawType
18tuple :: IParser T.RawType
17−tuple = do ts <- parens (commaSep expr)
20+ do ts <- parens (commaSep expr)
18− return $ case ts of
21+ case ts of
19− [t] -> t
22+ [t] -> return t
20− _ -> T.tupleOf ts
23+ _ -> return (T.tupleOf ts)
22record :: IParser T.RawType
26record :: IParser T.RawType
24− do char '{' ; whitespace
29+ whitespace
25− rcrd <- extended <|> normal
30+ rcrd <- extended <|> normal
26− dumbWhitespace ; char '}'
31+ dumbWhitespace
27− return rcrd
33+ return rcrd
29 normal = flip T.Record Nothing <$> commaSep field
35 normal = flip T.Record Nothing <$> commaSep field
@@ -39,38 +45,47 @@ record =
39 whitespace >> hasType >> whitespace
45 whitespace >> hasType >> whitespace
40 (,) lbl <$> expr
46 (,) lbl <$> expr
42capTypeVar :: IParser String
49capTypeVar :: IParser String
43−capTypeVar = intercalate "." <$> dotSep1 capVar
51+ intercalate "." <$> dotSep1 capVar
45constructor0 :: IParser T.RawType
54constructor0 :: IParser T.RawType
46constructor0 =
55constructor0 =
47− do name <- capTypeVar
56+ do name <- capTypeVar
48− return (T.Type (Var.Raw name))
57+ return (T.Type (Var.Raw name))
50term :: IParser T.RawType
60term :: IParser T.RawType
51−term = tuple <|> record <|> tvar <|> constructor0
62+ tuple <|> record <|> tvar <|> constructor0
53app :: IParser T.RawType
65app :: IParser T.RawType
55− do f <- constructor0 <|> try tupleCtor <?> "type constructor"
67+ do f <- constructor0 <|> try tupleCtor <?> "type constructor"
56− args <- spacePrefix term
68+ args <- spacePrefix term
57− return $ case args of
69+ case args of
58− [] -> f
70+ [] -> return f
59− _ -> T.App f args
71+ _ -> return (T.App f args)
61 tupleCtor = do
73 tupleCtor = do
62 n <- length <$> parens (many (char ','))
74 n <- length <$> parens (many (char ','))
63 let ctor = "_Tuple" ++ show (if n == 0 then 0 else n+1)
75 let ctor = "_Tuple" ++ show (if n == 0 then 0 else n+1)
64 return (T.Type (Var.Raw ctor))
76 return (T.Type (Var.Raw ctor))
66expr :: IParser T.RawType
79expr :: IParser T.RawType
68− do t1 <- app <|> term
81+ do t1 <- app <|> term
69− arr <- optionMaybe $ try (whitespace >> arrow)
82+ arr <- optionMaybe $ try (whitespace >> arrow)
70− case arr of
83+ case arr of
71− Just _ -> T.Lambda t1 <$> (whitespace >> expr)
84+ Just _ -> T.Lambda t1 <$> (whitespace >> expr)
72− Nothing -> return t1
85+ Nothing -> return t1
74constructor :: IParser (String, [T.RawType])
88constructor :: IParser (String, [T.RawType])
75−constructor = (,) <$> (capTypeVar <?> "another type constructor")
90+ (,) <$> (capTypeVar <?> "another type constructor")
76− <*> spacePrefix term
91+ <*> spacePrefix term