@@ -9,22 +9,28 @@ import qualified AST.Type as T
99import qualified AST.Variable as Var
1010import Parse.Helpers
1111
12+
1213tvar :: IParser T.RawType
13−tvar = T.Var <$> lowVar <?> "type variable"
14+tvar =
15+ T.Var <$> lowVar <?> "type variable"
1416
1517
1618tuple :: IParser T.RawType
17−tuple = do ts <- parens (commaSep expr)
18− return $ case ts of
19− [t] -> t
20− _ -> T.tupleOf ts
19+tuple =
20+ do ts <- parens (commaSep expr)
21+ case ts of
22+ [t] -> return t
23+ _ -> return (T.tupleOf ts)
24+
2125
2226record :: IParser T.RawType
2327record =
24− do char '{' ; whitespace
25− rcrd <- extended <|> normal
26− dumbWhitespace ; char '}'
27− return rcrd
28+ do char '{'
29+ whitespace
30+ rcrd <- extended <|> normal
31+ dumbWhitespace
32+ char '}'
33+ return rcrd
2834 where
2935 normal = flip T.Record Nothing <$> commaSep field
3036
@@ -39,38 +45,47 @@ record =
3945 whitespace >> hasType >> whitespace
4046 (,) lbl <$> expr
4147
48+
4249capTypeVar :: IParser String
43−capTypeVar = intercalate "." <$> dotSep1 capVar
50+capTypeVar =
51+ intercalate "." <$> dotSep1 capVar
52+
4453
4554constructor0 :: IParser T.RawType
4655constructor0 =
47− do name <- capTypeVar
48− return (T.Type (Var.Raw name))
56+ do name <- capTypeVar
57+ return (T.Type (Var.Raw name))
58+
4959
5060term :: IParser T.RawType
51−term = tuple <|> record <|> tvar <|> constructor0
61+term =
62+ tuple <|> record <|> tvar <|> constructor0
63+
5264
5365app :: IParser T.RawType
5466app =
55− do f <- constructor0 <|> try tupleCtor <?> "type constructor"
56− args <- spacePrefix term
57− return $ case args of
58− [] -> f
59− _ -> T.App f args
67+ do f <- constructor0 <|> try tupleCtor <?> "type constructor"
68+ args <- spacePrefix term
69+ case args of
70+ [] -> return f
71+ _ -> return (T.App f args)
6072 where
6173 tupleCtor = do
6274 n <- length <$> parens (many (char ','))
6375 let ctor = "_Tuple" ++ show (if n == 0 then 0 else n+1)
6476 return (T.Type (Var.Raw ctor))
6577
78+
6679expr :: IParser T.RawType
6780expr =
68− do t1 <- app <|> term
69− arr <- optionMaybe $ try (whitespace >> arrow)
70− case arr of
71− Just _ -> T.Lambda t1 <$> (whitespace >> expr)
72− Nothing -> return t1
81+ do t1 <- app <|> term
82+ arr <- optionMaybe $ try (whitespace >> arrow)
83+ case arr of
84+ Just _ -> T.Lambda t1 <$> (whitespace >> expr)
85+ Nothing -> return t1
86+
7387
7488constructor :: IParser (String, [T.RawType])
75−constructor = (,) <$> (capTypeVar <?> "another type constructor")
76− <*> spacePrefix term
89+constructor =
90+ (,) <$> (capTypeVar <?> "another type constructor")
91+ <*> spacePrefix term