Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Foo a where
  2.   fromFoo :: Maybe a -> Int
  3.  
  4. data Bar = Bar
  5. instance Foo Bar where
  6.   fromFoo (Just Bar) = 1
  7.   fromFoo _ = 0
  8.  
  9. parseBar :: String -> Maybe Bar
  10. parseBar "Bar" = Just Bar
  11. parseBar _ = Nothing
  12.  
  13. data Baz = Baz
  14. instance Foo Baz where
  15.   fromFoo (Just Baz) = 2
  16.   fromFoo _ = 0
  17.  
  18. parseBaz :: String -> Maybe Baz
  19. parseBaz "Baz" = Just Baz
  20. parseBaz _ = Nothing
  21.  
  22.  
  23. myFunction :: Bool -> String -> Int
  24. myFunction selector toParse = fromFoo $
  25.   if selector
  26.   then parseBar toParse
  27.   else parseBaz toParse
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement