[Haskell-cafe] Counterintuitive ScopedTypeVariables behaviour
Erik Hesselink
hesselink at gmail.com
Mon Aug 17 13:30:59 UTC 2020
On Mon, 17 Aug 2020 at 07:10, Anthony Clayden <anthony_clayden at clear.net.nz>
wrote:
> Hi Tom, I see nothing bizarre nor counterintuitive. Perhaps you need to retrain your intuitions ;-)
>
> > I have just noticed that with ScopedTypeVariables one can write the
> > following bizarre definition
> >
> > -- Inferred signature:
> > -- add :: Num a => a -> a -> a
> > add (x :: a) (y :: b) = x + y
>
> What do you think is bizarre? GHC makes a reasonable attempt to use the tyvar names you put in a signature -- remembering that alpha-renaming means the name is not really significant. I can get `add :: Num c => c -> c -> c`, etc.
>
>
I can't speak for Tom, but to me the above feels very similar to writing
something like:
add :: _ => a -> b -> _
add x y = x + y
But that doesn't type check, since the types `a` and `b` are not the same,
but `+` needs them to be.
Erik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20200817/bba3e304/attachment.html>
More information about the Haskell-Cafe
mailing list