Changes between Version 6 and Version 7 of MonomorphicPatternBindings


Ignore:
Timestamp:
Feb 1, 2007 1:53:27 PM (7 years ago)
Author:
simonpj@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MonomorphicPatternBindings

    v6 v7  
    5151In July I changed GHC (the HEAD) to make pattern bindings monomorphic by default.  (A binding of a simple variable is not considered to be a pattern binding.)  The flag {{{-fno-mono-pat-binds}}} restores the standard behaviour.  I deliberately made the new behaviour the default so that I'd hear of any breakage. 
    5252 
    53 The interesting observation is this: all of the libraries compile without a tremor, and I have received only one message remarking on the new behaviour.  Ross Paterson sent me this code 
     53The interesting observation is this: all of the libraries compile without a tremor, and I have received only two messages remarking on the new behaviour.   
     54 
     55=== First message === 
     56Ross Paterson sent me this code 
    5457{{{ 
    5558import Control.Monad.ST 
     
    6669          where f = case lf of { ListMap f -> f } 
    6770}}} 
     71'''Comment''': A polymorphic pattern binding isn't required in the above example, but the original code seems more elegant. Why not make monomorphism the default and permit polymorphism only when there is an explicit type signature on the binding? 
     72 
     73=== Second message === 
     74Tristan Allwood (tora at doc.ic.ac.uk) said this.   
     75I was recently bitten by the fact pattern bindings are monomorphic; 
     76admitadly I'm writing code to learn about theoretical typing issues and 
     77nothing mainstream/production; but (as I hope my ghci session should 
     78illustrate) the cause of the problem is difficult to isolate if you're 
     79not aware of the property (which I wasn't until Igloo on #haskell 
     80pointed me this way); 
     81{{{ 
     82  Prelude> :m +Data.Maybe 
     83 
     84  Prelude Data.Maybe> let f = (fromJust (Just id)) in (f 3, f False) 
     85  (3,False) 
     86 
     87  Prelude Data.Maybe> let (Just f) = (Just id) in (f 3, f False) 
     88 
     89  <interactive>:1:31: 
     90      No instance for (Num Bool) 
     91        arising from the literal `3' at <interactive>:1:31 
     92      Possible fix: add an instance declaration for (Num Bool) 
     93      In the first argument of `f', namely `3' 
     94      In the expression: f 3 
     95      In the expression: let (Just f) = (Just id) in (f 3, f False) 
     96}}} 
     97Ok, fine: except the reported type signatures are the same vis: 
     98{{{ 
     99  Prelude Data.Maybe> :t let f = (fromJust (Just id)) in f 
     100  let f = (fromJust (Just id)) in f :: forall a. a -> a 
     101 
     102  Prelude Data.Maybe> :t let (Just f) = (Just id) in f 
     103  let (Just f) = (Just id) in f :: forall a. a -> a 
     104}}} 
     105And just to cap it off, adding a layer of indirection... 
     106{{{ 
     107  Prelude Data.Maybe> let q = ( let (Just f) = (Just id) in f ) in (q 3, q False) 
     108  (3,False) 
     109}}} 
     110Simon's comment: yes, I guess this is a bit confusing.  But the same will happen in H98 if the type of f was overloaded.  And the example seems quite contrived.   
     111 
     112== Summary == 
     113 
    68114My conclusion: polymorphic pattern bindings is a feature that is virtually never used, and not even necessary then.  We should nuke them. 
    69115 
    70 Comment: A polymorphic pattern binding isn't required in the above example, but the original code seems more elegant. Why not make monomorphism the default and permit polymorphism only when there is an explicit type signature on the binding?