Guest User

Untitled

a guest
Oct 16th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. import Data.Tuple
  2. import Data.Maybe
  3. import Data.List
  4.  
  5. data MyDataType = Foo
  6. | Bar
  7. | Baz
  8. deriving (Enum,Eq,Show)
  9.  
  10. instance Enum MyDataType where
  11. fromEnum = fromJust . flip lookup table
  12. toEnum = fromJust . flip lookup (map swap table)
  13. table = [(Foo, 0), (Bar, 1), (Baz, 2)]
  14.  
  15.  
  16.  
  17.  
  18. $ ghc loo.hs
  19. [1 of 1] Compiling Main ( loo.hs, loo.o )
  20.  
  21. loo.hs:8:10: error: parse error on input ‘(’
  22. |
  23. 8 | deriving (Enum,Eq,Show)
  24. | ^
  25.  
Advertisement
Add Comment
Please, Sign In to add comment