2

In GHCi the following works just dandy:

let (≠) = (/=)

But trying to compile this from a source file results in an error:

(≠) = (/=)

Here is the error, for reference:

"Ambiguous type variable 'a0' arising from a use of '/=' prevents the constraint '(Eq a0)' from being solved."

What am I doing wrong?

crisis.sheep
  • 389
  • 4
  • 15

1 Answers1

6

You'll need to add a type signature, otherwise Haskell is trying to assign one specific type but gets confused due to the ambiguous type.

(≠) :: Eq a => a -> a -> Bool
(≠) = (/=)
Adam Smith
  • 52,157
  • 12
  • 73
  • 112
  • 6
    "Gets confused" is maybe not the most accurate way to phrase it, as that would imply that GHCi, which doesn't "get confused", is somehow more intelligent than GHC. The relevant keyword here is the monomorphism restriction. – sepp2k Dec 24 '18 at 09:04
  • @sepp2k that's true, this answer was badly phrased. – Adam Smith Dec 24 '18 at 09:06