- pAST :: Parser [Function]
- pAST = many pFunction >>= mapM \(id, args, body)->Function id args <$
- modify (\t->{t & tokens=body}) <*> pExpression <* pEof
+ pAST :: Parser [Either TypeDef Function]
+ pAST = many (Right <$> pFunction <|> Left <$> pTypeDef)
+ >>= mapM (either (pure o Left) \(id, args, body)->Right o
+ Function id args <$ modify (\t->{t & tokens=body}) <*> pExpression <* pEof)
+
+ pTypeDef :: Parser TypeDef
+ pTypeDef = TypeDef
+ <$ pToken TTDColon
+ <*> pId
+ <*> many pId
+ <* pToken TTEq
+ <*> (cons <$> pCons <*> many (pToken TTPipe *> pCons))
+ <* pToken TTSemiColon
+
+ pCons = tuple <$> pId <*> many pType
+
+ pType
+ = TInt <$ pTop ? (\t->t=:(TTIdent ['Int']))
+ <|> TBool <$ pTop ? (\t->t=:(TTIdent ['Bool']))
+ <|> TVar <$> pId
+ <|>
+:: Type
+ = TVar [Char]
+ | TTuple Type Type
+ | TInt
+ | TBool
+ | (-->) infixr 9 Type Type