Created
January 10, 2014 15:47
-
-
Save nnabeyang/8356766 to your computer and use it in GitHub Desktop.
『プログラミングHaskell』の関数型パーサーをStateTを使って書き直す ref: http://qiita.com/nnabeyang/items/97d67191758dabb50752
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
| ghci> parse nat "123" | |
| [(123, ""), (12, "3"), (1, "23")] |
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
| Nothing `mplus` ys = ys | |
| xs `mplus` _ = xs |
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
| 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