Advertisement
Guest User

Untitled

a guest
Oct 16th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 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. $ ghc loo.hs
  17. [1 of 1] Compiling Main ( loo.hs, loo.o )
  18.  
  19. loo.hs:8:16: error:
  20. Duplicate instance declarations:
  21. instance Enum MyDataType -- Defined at loo.hs:8:16
  22. instance Enum MyDataType -- Defined at loo.hs:10:10
  23. |
  24. 8 | deriving (Enum,Eq,Show)
  25. | ^^^^
  26. [haroldo@semiosis haskell]$
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement