0

My expectation is that the code sample below ought to compile

testOptionalEq = None == None
testEitherEq   = Left 1 == Left 1

testOptionalShow = show None
testEitherShow   = show (Left 1)

and yet each line results in a compilation error, either

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.

or

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.

Trying similar looking Haskell code in ghci works. One workaround is to give the values explicit type signatures (e.g. None : Optional Int), but it would be great if it worked without that.

Neil Mitchell
  • 9,090
  • 1
  • 27
  • 85

1 Answers1

0

Your code doesn't work in compiled Haskell, only in ghci, because ghci automatically enables the ExtendedDefaultRules extension. If you want this behaviour in DAML you need to explicitly turn on {-# LANGUAGE ExtendedDefaultRules #-} at the top of the file, then this code then works.

However, like Haskell, I wouldn't usually recommend turning on this extension. The cases were you don't have enough types available tend to be rare, and the restriction of this extension to "interactive classes" can make it quite confusing.

Neil Mitchell
  • 9,090
  • 1
  • 27
  • 85