@@ -9,21 +9,19 @@ import qualified AST.Type as T
9import qualified AST.Variable as Var
9import qualified AST.Variable as Var
10import Parse.Helpers
10import Parse.Helpers
12−type RawType = T.Type Var.Raw
14−tvar :: IParser RawType
12+tvar :: IParser T.RawType
15tvar = T.Var <$> lowVar <?> "type variable"
13tvar = T.Var <$> lowVar <?> "type variable"
17−list :: IParser RawType
15+list :: IParser T.RawType
18list = T.listOf <$> braces expr
16list = T.listOf <$> braces expr
20−tuple :: IParser RawType
18+tuple :: IParser T.RawType
21tuple = do ts <- parens (commaSep expr)
19tuple = do ts <- parens (commaSep expr)
22 return $ case ts of
20 return $ case ts of
24 _ -> T.tupleOf ts
22 _ -> T.tupleOf ts
26−record :: IParser RawType
24+record :: IParser T.RawType
28 do char '{' ; whitespace
26 do char '{' ; whitespace
29 rcrd <- extended <|> normal
27 rcrd <- extended <|> normal
@@ -46,15 +44,15 @@ record =
46capTypeVar :: IParser String
44capTypeVar :: IParser String
47capTypeVar = intercalate "." <$> dotSep1 capVar
45capTypeVar = intercalate "." <$> dotSep1 capVar
49−constructor0 :: IParser RawType
47+constructor0 :: IParser T.RawType
50constructor0 =
48constructor0 =
51 do name <- capTypeVar
49 do name <- capTypeVar
52 return (T.Data (Var.Raw name) [])
50 return (T.Data (Var.Raw name) [])
54−term :: IParser RawType
52+term :: IParser T.RawType
55term = list <|> tuple <|> record <|> tvar <|> constructor0
53term = list <|> tuple <|> record <|> tvar <|> constructor0
57−app :: IParser RawType
55+app :: IParser T.RawType
59 do name <- capTypeVar <|> try tupleCtor <?> "type constructor"
57 do name <- capTypeVar <|> try tupleCtor <?> "type constructor"
60 args <- spacePrefix term
58 args <- spacePrefix term
@@ -64,7 +62,7 @@ app =
64 n <- length <$> parens (many (char ','))
62 n <- length <$> parens (many (char ','))
65 return $ "_Tuple" ++ show (if n == 0 then 0 else n+1)
63 return $ "_Tuple" ++ show (if n == 0 then 0 else n+1)
67−expr :: IParser RawType
65+expr :: IParser T.RawType
69 do t1 <- app <|> term
67 do t1 <- app <|> term
70 arr <- optionMaybe $ try (whitespace >> arrow)
68 arr <- optionMaybe $ try (whitespace >> arrow)
@@ -72,6 +70,6 @@ expr =
72 Just _ -> T.Lambda t1 <$> (whitespace >> expr)
70 Just _ -> T.Lambda t1 <$> (whitespace >> expr)
73 Nothing -> return t1
71 Nothing -> return t1
75−constructor :: IParser (String, [RawType])
73+constructor :: IParser (String, [T.RawType])
76constructor = (,) <$> (capTypeVar <?> "another type constructor")
74constructor = (,) <$> (capTypeVar <?> "another type constructor")
77 <*> spacePrefix term
75 <*> spacePrefix term