Can we conclude that there is no way to calculate maxBound - minBound in Haskell for an arbitrary type of Enum and Bounded ? Or am I missing a trick / hack? This is what I have that obviously cannot work:
difference :: (Enum a, Bounded a) => Int difference = fromEnum maxBound - fromEnum minBound
Mistake:
Foo.hs:37:1: Ambiguous constraint `Enum a' At least one of the forall'd type variables mentioned by the constraint must be reachable from the type after the '=>' In the type signature for `difference': difference :: (Enum a, Bounded a) => Int Foo.hs:37:1: Ambiguous constraint `Bounded a' At least one of the forall'd type variables mentioned by the constraint must be reachable from the type after the '=>' In the type signature for `difference': difference :: (Enum a, Bounded a) => Int
I understand why I get this error - there is no real term with type a , so it cannot understand what a . The question is is there a way around this.
haskell
Luis casillas
source share