diff --git a/examples/parser.hs b/examples/parser.hs new file mode 100644 index 0000000..cf77143 --- /dev/null +++ b/examples/parser.hs @@ -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"