Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo a where
- fromFoo :: Maybe a -> Int
- data Bar = Bar
- instance Foo Bar where
- fromFoo (Just Bar) = 1
- fromFoo _ = 0
- parseBar :: String -> Maybe Bar
- parseBar "Bar" = Just Bar
- parseBar _ = Nothing
- data Baz = Baz
- instance Foo Baz where
- fromFoo (Just Baz) = 2
- fromFoo _ = 0
- parseBaz :: String -> Maybe Baz
- parseBaz "Baz" = Just Baz
- parseBaz _ = Nothing
- myFunction :: Bool -> String -> Int
- myFunction selector toParse = fromFoo $
- if selector
- then parseBar toParse
- else parseBaz toParse
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement