
I'd like to make "Day" an instance of class "Enum," but the definition of toEnum below seems to be completely wrong, because integers seem not permit pattern matching. How is toEnum defined? Thanks. data Day = Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday deriving (Eq, Ord, Show) instance Enum Day where fromEnum Sunday = 0 fromEnum Monday = 1 fromEnum Tuesday = 2 fromEnum Wednesday = 3 fromEnum Thursday = 4 fromEnum Friday = 5 fromEnum Saturday = 6 toEnum 0 = Sunday toEnum 1 = Monday toEnum 2 = Tuesday toEnum 3 = Wednesday toEnum 4 = Thursday toEnum 5 = Friday toEnum 6 = Saturday _________________________________________________________________ Hotmail is redefining busy with tools for the New Busy. Get more from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:W...

2010/5/21 R J
I'd like to make "Day" an instance of class "Enum," but the definition of toEnum below seems to be completely wrong, because integers seem not permit pattern matching. How is toEnum defined? Thanks.
Hi, What error are you getting when you try your class instance? Thanks, Antoine

R J
I'd like to make "Day" an instance of class "Enum," but the definition of toEnum below seems to be completely wrong, because integers seem not permit pattern matching. How is toEnum defined? Thanks.
You could try using guards:
toEnum x | x == 0 = Sunday | x == 1 = Monday | x == 2 = Tuesday | x == 3 = Wednesday | x == 4 = Thursday | x == 5 = Friday | x == 6 = Saturday | otherwise = error "bad enum"
BTW if none of your constructors have fields you can just add Enum to
the "deriving (...)" list for your type, and the compiler will write
basically the same instance for you.
G.
--
Gregory Collins
participants (3)
-
Antoine Latter
-
Gregory Collins
-
R J