我是否可以得出结论,maxBound - minBound
在 Haskell 中无法计算任意类型Enum
的Bounded
类型?还是我错过了一些技巧/黑客?这就是我所拥有的,这显然行不通:
difference :: (Enum a, Bounded a) => Int
difference = fromEnum maxBound - fromEnum minBound
错误:
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
我理解为什么会出现该错误- type 中没有实际术语a
,因此无法弄清楚是什么a
。问题是是否有办法解决这个问题。