[Haskell-cafe] is monomorphism restriction necessary?

Roman Cheplyaka roma at ro-che.info
Sat Apr 16 20:10:28 UTC 2016

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)
          len :: a
          len = genericLength xs


More information about the Haskell-Cafe mailing list