Add parser example

This commit is contained in:
Chris Done 2019-11-25 14:33:31 +00:00
parent 19e0e51d9d
commit 3d0ec5488a

16
examples/parser.hs Normal file
View File

@ -0,0 +1,16 @@
data Result a = OK a String | Error String
data Parser a = Parser (String -> Result a)
parseBool =
Parser
(\string ->
case take 4 string of
"True" -> OK True (drop 4 string)
_ ->
case take 5 string of
"False" -> OK False (drop 5 string)
_ -> Error (append "Expected a bool, but got: " string))
runParser =
\p s ->
case p of
Parser f -> f s
main = runParser parseBool "TrueFalse"