[Haskell-cafe] type checking failure curiosity

Richard Eisenberg lists at richarde.dev
Tue Nov 16 16:26:27 UTC 2021

Perhaps you're right -- the monomorphism restriction wouldn't fire there, because there's no constraint to monomorphise. Instead, you just want a monomorphic `new`.... but I see no easy way (other than a type signature) to get this.

Think of it this way: without the type annotation, you've said `let new = undefined in ...`. Now, replace `new` with `undefined` everywhere you've written `new`. Your code will include `null undefined`, which is indeed irresolvably ambiguous.


> On Nov 16, 2021, at 7:44 AM, Julian Bradfield <jcb+hc at julianbradfield.org> wrote:
>> My guess is that you've disabled the monomorphism restriction somehow... but you need the MR to type-check this code. Without the MR, `new` gets a type `forall a. a`, which gets specialized differently in `new`'s two occurrences, meaning that the type information from the second occurrence doesn't affect the first one... which you need it to in order to type-check the `null new` call.
> Hm. I see the MR is off at the command prompt by default, but on in
> compiled modules. The offending code was in a module starting:
> module CLTutorial9 where
> import Prelude hiding (lookup)
> import Data.Set(Set, insert, empty, member, fromList, toList,
>                 union,intersection, size, singleton, (\\))
> import qualified Data.Set as S
> import Test.QuickCheck
> import Data.Char
> I haven't knowingly done any thing to turn off the MR.

More information about the Haskell-Cafe mailing list