[Haskell] Re: Enum class

Sebastian Sylvan sebastian.sylvan at gmail.com
Sun Jan 9 05:48:00 EST 2005


On 09 Jan 2005 07:56:58 +0100, Peter Simons <simons at cryp.to> wrote:
> Jaime Nino writes:
> 
>  > I would like to write a function with type
>  >    next :: Enum a => a -> a
>  > which will wrap a values around [...].
> 
> You'll need (Bounded a, Enum a) to implement that. The
> function you are looking for is 'maxBound'. Enumerable types
> are not necessarily bounded in the general case, just think
> of the natural numbers for an example of an enumerable set
> that is not.
> 

He'll also need Eq a, right? How else does he investigate wether the
value is equal to maxBound?

One could use exceptions, I suppose, and catch the exception which
arises from trying to use succ on maxBound. But then  you'll need to
be in the IO monad, unless you use unsafePerformIO =)

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


More information about the Haskell mailing list