[Haskell-cafe] Type inference for lambda function
Ben Franksen
ben.franksen at online.de
Sun Oct 31 18:16:17 UTC 2021
The MonomorphismRestriction should be eliminated from the next Haskell
standard.
Am 26.10.21 um 15:53 schrieb Richard Eisenberg:
>> On Oct 21, 2021, at 2:48 PM, David Feuer <david.feuer at gmail.com>
>> wrote:
>>
>> This is the dreaded monomorphism restriction, which is turned on by
>> default in modules but turned off by default in GHCi. Because your
>> function is not "syntactically" a function (i.e., there are no
>> arguments to the left of the = sign), and has no type signature,
>> the type checker insists on it having a monomorphic type. Unless
>> there's a use of it in the module forcing it to a particular type,
>> the defaulting rules come into play, and a variable with a `Num`
>> constraint defaults, by default, to `Integer`.
>
> Indeed -- but I will offer a tiny nuance: the type checker only
> insists that the type has no constraints, not that it is fully
> monomorphic. That is, writing `myId = id` will produce a polymorphic
> myId because there are no constraints on id, while `myPlus = (+)`
> will be monomorphic because of the constraint on (+).
--
I would rather have questions that cannot be answered, than answers that
cannot be questioned. -- Richard Feynman
More information about the Haskell-Cafe
mailing list