Created
April 17, 2017 13:21
-
-
Save joonazan/5354cbef67595074c29b3a47ca3a6247 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typeSignature = | |
lazy <| \() -> | |
sepBy (whitespace *> string "->" *> whitespace) nonFunctionType | |
|> andThen ( | |
reducer TArrow | |
>> Maybe.map succeed | |
>> Maybe.withDefault (fail "expected type, got nothing") | |
) | |
reducer : (a -> a -> a) -> List a -> Maybe a | |
reducer f list = | |
case list of | |
last :: [] -> | |
Just last | |
head :: tail -> | |
reducer f tail | |
|> Maybe.map (f head) | |
[] -> | |
Nothing | |
nonFunctionType : Parser s Type | |
nonFunctionType = | |
let | |
withArguments = | |
TUnion | |
<$> uppercaseName | |
<*> (many onePartType) | |
in | |
or withArguments onePartType | |
onePartType : Parser s Type | |
onePartType = | |
choice | |
[ typeName | |
, typeVar | |
, parentheses | |
--, tuple | |
--, record | |
] | |
typeName : Parser s Type | |
typeName = | |
(flip TUnion <| []) <$> uppercaseName | |
-- TODO: properly assign type variables | |
typeVar : Parser s Type | |
typeVar = | |
always (TAny 1) <$> lowercaseName | |
parentheses : Parser s Type | |
parentheses = | |
parens typeSignature |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment