Advertisement
Guest User

Untitled

a guest
Oct 16th, 2021
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. instance Enum MyDataType where
  2. fromEnum = fromJust . flip lookup table
  3. toEnum = fromJust . flip lookup (map swap table)
  4. table = [(Foo, 0), (Bar, 1), (Baz, 2)]
  5.  
  6. =============================
  7.  
  8. instance Enum MyDataType where
  9. fromEnum Foo = 0
  10. fromEnum Bar = 1
  11. fromEnum Bax = 2
  12. toEnum 0 = Foo
  13. toEnum 1 = Bar
  14. toEnum 2 = Baz
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement