The monomorphism restriction and monomorphic pattern bindings
marlowsd at gmail.com
Thu Apr 24 13:12:27 EDT 2008
Iavor Diatchki wrote:
> I should also point out that if we were to adopt the MBP rule, we
> would have to adjust the definition of what pattern bindings mean.
> For example, I think that this is how things are desugared at the
> (x,y) = e
> new_var = e
> x = case new_var of (v,_) -> v
> y = case new_var of (_,v) -> v
The report doesn't actually mention this translation although it is
widely used to implement pattern bindings, and in some compilers (not
GHC) the translation is done before type checking.
What's interesting to me is that perhaps this gives us a way to
understand what the static semantics of pattern bindings should be,
absent MPB. e.g.
(x,y) = (negate,show)
(Simon's example) translates to
z = (negate,show)
x = fst z
y = snd z
and we can see why both x and y end up generalised over both
z :: (Num a, Show b) => (a -> a, b -> String)
and this also explains why the pattern-bound variables don't have to be
generalised over all the type variables. e.g. in
z = (id,id)
x = fst z
y = snd z
z :: forall a b . (a->a, b->b)
x :: forall a . a -> a
x :: forall a b . a -> a
because the generalisation step for x only generalises over the type
variables in the type arising from its right-hand side.
> It seems that under MBP the second program is not equivalent to the
> first because it is more polymorphic.
> On Wed, Apr 23, 2008 at 10:32 AM, Simon Marlow <marlowsd at gmail.com> wrote:
>> The current proposal on the table for what to do about the monomorphism
>> restriction (henceforth MR) is
>> * remove the MR entirely
>> * adopt Monomorphic Pattern Bindings (MPB)
>> Right now, the committee is almost uniformly in favour of dropping the MR,
>> and most of us are coming round to the idea of MPB. Since this area has
>> historically been difficult to achieve a concensus on, I'm excited that we
>> appear to be close to making a decision, and a good one at that!
>> The arguments for removing the MR are pretty well summarised on the wiki:
>> You can read about MPB here:
>> GHC has implemented MPB by default (i.e. we deviate slightly from Haskell
>> 98) since 6.8.1.
>> The nice thing about the combination of removing MR and adopting MPB is
>> that we retain a way to explicitly declare monomorphic bindings. These are
>> monomorphic bindings:
>> ~x = e
>> x at _ = e
>> or if you don't mind a strict binding: !x = e. The wiki points out that
>> (x) = e
>> would also be monomorphic, but arguably this is in poor taste since we
>> expect (x) to mean the same as x everywhere.
>> Haskell-prime mailing list
>> Haskell-prime at haskell.org
More information about the Haskell-prime