[Haskell] Enum class

Sebastian Sylvan sebastian.sylvan at gmail.com
Sun Jan 9 00:51:02 EST 2005


On Fri, 07 Jan 2005 18:57:01 -0600, Jaime Nino <jaime at cs.uno.edu> wrote:


> where value is the last value of a.
                              ^^^^^^^^^^^^^^^^

> I have not found any functionality on Enum types to do this. In
> particular how to
> specify the last element of any Enum type, or how to determine the
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> number of elements in an Enum type.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It looks as if you really want to use the type class Bounded as well.

You can use maxBound and minBound to find the last and first value of
a Bounded type.

If you impose the additional constraint Eq and Bounded you can write
next like so:

next :: (Enum a, Bounded a, Eq a) => a -> a
next x | x == maxBound = minBound
          | otherwise = succ x

/S
-- 
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862


More information about the Haskell mailing list