iavor.diatchki at gmail.com
Sat Oct 14 16:59:38 EDT 2006
On 10/14/06, Bulat Ziganshin <bulat.ziganshin at gmail.com> wrote:
> Hello haskell-prime,
> first is the monomorphism restriction. why isn't it possible to check
> _kind_ of parameter-less equation and apply monomorphism restrictions
> only to values of kind '*'? so, this:
> sum = foldr1 (*)
> will become polymorphic because its kind is '*->*' while this
Kinds are use to classify _types_ and not _expressions_. In this
case, the expression has the type "a -> a", with the constraint that
"a" is a numeric type.
This type is of kind *. In general, all the executable parts of a
Haskell program have types that are of kind *. The things that have
kinds like "* -> *" are type constructors.
On the other hand, you might wonder why not use the _type_ of an
expression in the monomorphism restriction (MR) and only monomorphize
expressions of a non-functional type. The reason this would not work
is that the MR is used to avoid repeated evaluation of overloaded
expressions when they are instantiated to the same types, but the type
of an expression does not tell us if the expression is already
evaluated. Remember that in a functional language functions are values
like any other, and so we might have to do computation to evaluate
them. This is why the MR uses a syntactic heuristic.
Having said that, many people find the MR weird because it is kind of
implementation specific. Even without the MR, a compiler could
perform an optimization that notices that a value is being
instantiated with the same dictionary multiple times and avoid the
repeated evaluation. The MR is especially weird if we consider the
fact that the Haskell report does not even require implementations to
have sharing (e.g., call by name semantics are OK), so implementation
may duplicate evaluation at will...
More information about the Haskell-prime