[GHC] #14782: typeclass polymorphism defeats bang patterns
GHC
ghc-devs at haskell.org
Fri Feb 9 09:10:43 UTC 2018
#14782: typeclass polymorphism defeats bang patterns
-------------------------------------+-------------------------------------
Reporter: dmwit | Owner: (none)
Type: bug | Status: closed
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.2
Resolution: invalid | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Changes (by simonpj):
* status: new => closed
* resolution: => invalid
Comment:
It is a bit confusing.
See [http://downloads.haskell.org/~ghc/master/users-
guide/glasgow_exts.html#recursive-and-polymorphic-let-bindings the manual
entry for semantics of let bindings]
{{{
let n :: Num a => a; !n = undefined in return ()
means
let n :: Num a => a
n = undefined
in n `seq` return ()
which, after elaboration of dictionaries etc means
let n = /\a. \(d::Num a). undefined
in n `seq` return ()
}}}
So the `seq` sees a lambda and does nothing.
---------
As to the "conflicts with the MR" message, consider
{{{
f :: forall a. Num a => a -> a
Just f = e
}}}
and consult
[https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-880004.5
the Haskell report on the monomorphism restriction]. It says that the MR
applies unless "an explicit type signature is given for every variable in
the group that is bound by simple pattern binding"; and "Recall that ... a
simple pattern binding is a pattern binding in which the pattern consists
of only a single variable". So here `f` is not bound by a simple pattern
binding and hence falls under the MR, signature or no signature.
It's the same for your pattern binding `x at n`. You may say "but it's still
simple" but that's not what the rules currently say.
Incidentally, there's a bad typo in the Haskell 98 and Haskell 2010
reports. Under
[https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-860004.4.3.2
pattern bindings] both say "A simple pattern binding has form p = e"; but
of course ''all'' pattern bindings have that form. It should say "A
simple pattern binding has form x = e, where x is a variable".
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14782#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list