[Haskell-beginners] Change in type that I don't understand

David McBride toad3k at gmail.com
Fri Jan 27 15:53:47 UTC 2017

Sorry let me elaborate.  The type of f depends on its argument.  The
argument could be anything that the caller passes in so long as it is
an instance of Num.  If the user passes in Int or Integer or Float, it
has to handle all those cases.  It can't just type restrict the
argument to Int, that is likely not what the user wanted.  If he had
he would have type restricted it himself.

g on the other hand has complete control over its own type.  If mm
restriction is enabled and there is no type declaration then it is
reasonable for it to default to a concrete type so that it only has to
generate only one possible code path.

If it isn't enabled then it will try to be as polymorphic as possible,
at the cost of being flexible enough to return any type that is an
instance of Num.

On Fri, Jan 27, 2017 at 10:17 AM, Daniel Trstenjak
<daniel.trstenjak at gmail.com> wrote:
> On Fri, Jan 27, 2017 at 08:35:08AM -0500, David McBride wrote:
>> If you have the Monomorphism restriction set, it will choose types
>> based on the type defaulting rules (Num changes to Integer).  This is
>> because polymorphic code is slower than code that has concrete types.
> But why didn't the defaulting rules have been applied for both: 'f' and 'g'?
> Greetings,
> Daniel
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

More information about the Beginners mailing list