我的期望是下面的代码样本应编译
testOptionalEq = None == None
testEitherEq = Left 1 == Left 1
testOptionalShow = show None
testEitherShow = show (Left 1)
但是每行会导致汇编误差,要么
Ambiguous type variable `a1' arising from a use of `=='
prevents the constraint `(Eq a1)' from being solved.
Probable fix: use a type annotation to specify what `a1' should be.
或
Ambiguous type variable `a0' arising from a use of `show'
prevents the constraint `(Show a0)' from being solved.
Probable fix: use a type annotation to specify what `a0' should be.
在ghci
中尝试类似外观的Haskell代码工作。一个解决方法是给出显式类型的签名(例如None : Optional Int
(,但是如果没有该值,它将很棒。
您的代码仅在conkell中不起作用,仅在ghci
中,因为ghci
会自动启用ExtendedDefaultRules
扩展名。如果您希望在DAML中进行此行为,则需要在文件顶部明确打开{-# LANGUAGE ExtendedDefaultRules #-}
,然后此代码可行。
但是,就像Haskell一样,我通常不建议打开此扩展名。如果您没有足够的可用类型的情况,则往往很少见,并且此扩展对"交互式类别"的限制会使它变得非常混乱。