[Haskell-cafe] Circular enums

Ben Butler-Cole ben at bridesmere.com
Sat Feb 2 19:05:58 EST 2008


On 
Feb 
2, 
2008, 
at 
18:41 
, I
wrote:

>  
  
 
No 
instance 
for 
(Bounded 
a)
>  
  
  
 
arising 
from 
use 
of 
`maxBound' 
at 
Hbot.hs:6:34-41
> 
(...)
> 
My 
(clearly 
flawed) 
understanding 
of 
the 
signature 
I've 
specified  
> 
for 
'turn' 
means 
*exactly* 
that 
a 
is 
Bounded.

Brandon Allbery replied:

> The 
problem 
is 
that 
the 
scope 
of 
a 
is 
the 
type 
signature; 
it 
does  
> *not* 
extend 
to 
the 
definition.
>
> You 
can 
try 
omitting 
the 
type 
on 
maxBound 
and 
minBound, 
or 
you
> can enable 
the 
scoped 
type 
variables 
extension

Thank you. This compiles fine with the Glasgow extensions turned on as long as the type in the function signature is universally quantified:

turn :: forall a. (Enum a, Bounded a) => Int -> a -> a
turn n e = toEnum (add (fromEnum (maxBound::a) + 1) (fromEnum e) n)
    where
      add mod x y = (x + y + mod) `rem` mod






More information about the Haskell-Cafe mailing list