Jump to content

Haskell Enum

- - - - -

  • Please log in to reply
1 reply to this topic

#1
kutasek

kutasek

    Newbie

  • Members
  • Pip
  • 1 posts
Hello.
I must do following exercise, but i don't know how. Have anybody an idea?

class Enum a where
toEnum :: a  Int
fromEnum :: Int  a

Is it possible to declare (a,b) as a member of
class Enum, given that both a and b are instances
of Enum?

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
class Enum a where

    toEnum :: a -> Int

    fromEnum :: Int -> a

    takeTwoEnums :: Enum b => (a, b) -> Int
Don't know what you're trying to do but there you go. I think you're trying to look at this from a far too OOP standpoint, what do you mean by "member"? Type classes have no guaranteed data members, only functions which are guaranteed to work on the passed data values. It's far superior to clumping data together in inefficient and thread-unsafe class objects.
Wow I changed my sig!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users