[Haskell-cafe] How to fix ambiguous type variable?

Tom Ellis tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk
Thu Jun 13 09:53:15 UTC 2019


On Thu, Jun 13, 2019 at 04:46:25AM -0400, Viktor Dukhovni wrote:
> > On Jun 13, 2019, at 4:25 AM, Boris <boris at d12frosted.io> wrote:
> > 
> > Agree, a good point. And actually, your variant works without any extensions.
> 
> Well, in a sense it is working with an "extension", just one that
> happens to be on by default and is required in Haskell 98.  Namely,
> what makes it work is the "MonomorphismRestriction".  If you specify:
> 
> 	{-# LANGUAGE NoMonomorphismRestriction #-}
> 
> then the example stops working.  I like the posted example as an
> exceptionally clear illustration of the MonomorphismRestriction.

And for the record, this version requires no extension nor unextension:

    {-# LANGUAGE NoMonomorphismRestriction #-}
    
    module Check where
    
    someCheck :: (Show a, Read a, Eq a) => String -> a -> Bool
    someCheck = someCheck' read
      where someCheck' r s v = (r . show . r $ s) == v


More information about the Haskell-Cafe mailing list