#2806: Require bang-patterns for unlifted bindings
---------------------------------+------------------------------------------
    Reporter:  simonpj           |        Owner:                  
        Type:  feature request   |       Status:  new             
    Priority:  normal            |    Milestone:  6.12.1          
   Component:  Compiler          |      Version:  6.8.3           
    Severity:  normal            |   Resolution:                  
    Keywords:                    |   Difficulty:  Unknown         
    Testcase:                    |           Os:  Unknown/Multiple
Architecture:  Unknown/Multiple  |  
---------------------------------+------------------------------------------
Comment (by simonpj):

 We're getting ourselves confused here. In the rest of this comment I'll
 write down a more formal account of what I think The Rules should be. If
 we can agree them, then we can implement them and put them in the user
 manual.

 First, let's agree that the semantics of bang patterns is defined here:
   * http://www.haskell.org/ghc/docs/latest/html/users_guide/bang-
 patterns.html

 This ticket is concerned with patterns that bind variables of unlifted
 type (e.g. `Int#`).  I propose the following rule:

   * A pattern `p` is '''strict down to''' `v` iff `v` does not appear
 under a lazy-pattern tilde "`~`".

   * A variable `v` of unlifted type may be bound by a pattern only in the
 following situations:
     * In a lambda or `case`, only by a pattern that is strict down to `v`.
     * In a `let` or `where`, only by a binding `!p = e` where `p` is
 strict down to `v`.


 Rationale: variables of unlifted type cannot be bound to a thunk, so the
 pattern must eagerly match all the way down to `v`.

 Examples. Suppose `v::Int#`.  Then here are some legal bindings:
 {{{
 \v -> e
 \(x, I# v) -> e
 let !v = e in b
 let !(x, I# v) = e in b
 \(x, !(I# v)) -> e       -- The inner ! is legal but not required
 \(x, I# !v) -> e         -- The ! on v is legal but not required
 }}}
 Here are some illegal ones
 {{{
 \~(I# v) -> e                -- Under a tilde
 let I# v = e in b            -- No bang on the pattern binding
 let !(x, ~(I# v)) = e in b   -- Under a tilde
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2806#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to