Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.Tuple
- import Data.Maybe
- import Data.List
- data MyDataType = Foo
- | Bar
- | Baz
- deriving (Enum,Eq,Show)
- instance Enum MyDataType where
- fromEnum = fromJust . flip lookup table
- toEnum = fromJust . flip lookup (map swap table)
- table = [(Foo, 0), (Bar, 1), (Baz, 2)]
- $ ghc loo.hs
- [1 of 1] Compiling Main ( loo.hs, loo.o )
- loo.hs:8:16: error:
- Duplicate instance declarations:
- instance Enum MyDataType -- Defined at loo.hs:8:16
- instance Enum MyDataType -- Defined at loo.hs:10:10
- |
- 8 | deriving (Enum,Eq,Show)
- | ^^^^
- [haroldo@semiosis haskell]$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement