... | ... | @@ -80,7 +80,12 @@ So this proposal makes the bang-pattern proposal easier to describe [ http://hac |
|
|
In 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.
|
|
|
|
|
|
|
|
|
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
|
|
|
The interesting observation is this: all of the libraries compile without a tremor, and I have received only two messages remarking on the new behaviour.
|
|
|
|
|
|
### First message
|
|
|
|
|
|
|
|
|
Ross Paterson sent me this code
|
|
|
|
|
|
```wiki
|
|
|
import Control.Monad.ST
|
... | ... | @@ -100,8 +105,59 @@ runMap lf as = runST (f as) |
|
|
where f = case lf of { ListMap f -> f }
|
|
|
```
|
|
|
|
|
|
**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?
|
|
|
|
|
|
My conclusion: polymorphic pattern bindings is a feature that is virtually never used, and not even necessary then. We should nuke them.
|
|
|
### Second message
|
|
|
|
|
|
|
|
|
Tristan Allwood (tora at doc.ic.ac.uk) said this.
|
|
|
I was recently bitten by the fact pattern bindings are monomorphic;
|
|
|
admitadly I'm writing code to learn about theoretical typing issues and
|
|
|
nothing mainstream/production; but (as I hope my ghci session should
|
|
|
illustrate) the cause of the problem is difficult to isolate if you're
|
|
|
not aware of the property (which I wasn't until Igloo on \#haskell
|
|
|
pointed me this way);
|
|
|
|
|
|
```wiki
|
|
|
Prelude> :m +Data.Maybe
|
|
|
|
|
|
Prelude Data.Maybe> let f = (fromJust (Just id)) in (f 3, f False)
|
|
|
(3,False)
|
|
|
|
|
|
Prelude Data.Maybe> let (Just f) = (Just id) in (f 3, f False)
|
|
|
|
|
|
<interactive>:1:31:
|
|
|
No instance for (Num Bool)
|
|
|
arising from the literal `3' at <interactive>:1:31
|
|
|
Possible fix: add an instance declaration for (Num Bool)
|
|
|
In the first argument of `f', namely `3'
|
|
|
In the expression: f 3
|
|
|
In the expression: let (Just f) = (Just id) in (f 3, f False)
|
|
|
```
|
|
|
|
|
|
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? |
|
|
|
|
|
Ok, fine: except the reported type signatures are the same vis:
|
|
|
|
|
|
```wiki
|
|
|
Prelude Data.Maybe> :t let f = (fromJust (Just id)) in f
|
|
|
let f = (fromJust (Just id)) in f :: forall a. a -> a
|
|
|
|
|
|
Prelude Data.Maybe> :t let (Just f) = (Just id) in f
|
|
|
let (Just f) = (Just id) in f :: forall a. a -> a
|
|
|
```
|
|
|
|
|
|
|
|
|
And just to cap it off, adding a layer of indirection…
|
|
|
|
|
|
```wiki
|
|
|
Prelude Data.Maybe> let q = ( let (Just f) = (Just id) in f ) in (q 3, q False)
|
|
|
(3,False)
|
|
|
```
|
|
|
|
|
|
|
|
|
Simon'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.
|
|
|
|
|
|
## Summary
|
|
|
|
|
|
|
|
|
My conclusion: polymorphic pattern bindings is a feature that is virtually never used, and not even necessary then. We should nuke them. |