Created
July 24, 2014 07:39
-
-
Save davidxifeng/9055f580af80d4f9f148 to your computer and use it in GitHub Desktop.
fail mzero and Parser
This file contains 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
import Data.Csv | |
import Control.Monad | |
import Control.Applicative | |
-- 2014-07-24 15:26:22 fail and mzero | |
data Test = A | B | C | |
deriving (Show, Read) | |
instance FromField Test where | |
parseField "A" = pure A | |
parseField "B" = pure B | |
parseField "C" = pure C | |
--parseField _ = fail "wrong input" | |
parseField _ = mzero | |
tp :: Parser Test | |
tp = parseField "Z" | |
test :: Either String Test | |
test = runParser tp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment