[Haskell-cafe] is monomorphism restriction necessary?

Alexey Muranov alexey.muranov at gmail.com
Sat Apr 16 20:23:28 UTC 2016


On Saturday, April 16, 2016 at 10:10:37 PM UTC+2, Roman Cheplyaka wrote:
>
> On 04/16/2016 10:22 PM, Alexey Muranov wrote: 
> > Could you show me, please, how to use scoped type variables to avoid MR 
> > in this example? 
>
> All MR does is it prevents a binding from being generalized. Another way 
> to achieve 
> that would be to give that binding a (monomorphic) type signature. Without 
> scoped t.v., you can't give a signature to 'len' while keeping 'f' 
> polymorphic 
> in the return type. With scoped t.v., you can: 
>
>   f :: forall a b . Num a => [b] -> (a,a) 
>   f xs = (len, len) 
>       where 
>           len :: a 
>           len = genericLength xs 
>

Great, thanks for the explanation (i'll think about it).  If i have 
understood correctly, having scoped type variables, MR is no longer needed 
at all then.

Alexey.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160416/f8139c8b/attachment.html>


More information about the Haskell-Cafe mailing list