Skip to content

Instantly share code, notes, and snippets.

@nnabeyang
Created January 10, 2014 15:47
Show Gist options
  • Select an option

  • Save nnabeyang/8356766 to your computer and use it in GitHub Desktop.

Select an option

Save nnabeyang/8356766 to your computer and use it in GitHub Desktop.
『プログラミングHaskell』の関数型パーサーをStateTを使って書き直す ref: http://qiita.com/nnabeyang/items/97d67191758dabb50752
ghci> parse nat "123"
[(123, ""), (12, "3"), (1, "23")]
Nothing `mplus` ys = ys
xs `mplus` _ = xs
eval :: String -> Int
eval xs = case (parse expr xs) of
Just (n, "") -> n
Just (_, out) -> error ("unused input " ++ out)
failure -> error "invalid input"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment