Created
April 17, 2017 13:21
-
-
Save joonazan/d4c0cfd9018719a9532dccba14bc4531 to your computer and use it in GitHub Desktop.
This file contains hidden or 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