PROPOSAL: Restrict the type of (^), (^^), and add genericPower, genericPower'

Henning Thielemann lemming at henning-thielemann.de
Sat Nov 17 13:11:22 EST 2007


On Sat, 17 Nov 2007, Cale Gibbard wrote:

> On 17/11/2007, Ian Lynagh <igloo at earth.li> wrote:
>
> > This proposal is about making (^) and (^^) consistent with everything
> > else. Making everything use Integer rather than Int is an orthogonal
> > question.
> >
> > Someone could also make a Prelude.Integer module, that exports
> >     foo :: ... Integer ...
> >     foo = genericFoo
> > for various foo which are specialised to Int in Prelude, and reexports
> > all other functions from Prelude. Getting rid of implicit Prelude
> > imports would help too.
> >
> >
> > Thanks
> > Ian
>
> I don't want the types specialised to Integer either though. I'd want
> to have the types be as generic as possible, but include appropriate
> pragmas to tell GHC how to optimise when they're applied
> monomorphically.

As Ian pointed to, general types for exponents are rarely used in the code
he explored. This is also my experience from doing math with Haskell. Did
you make a different experience? The proposal isn't about removing the
polymorphism of (^), but to shift it to an alphanumerically named
function. I find "to have the types be as generic as possible" isn't
always a good design strategy, especially in this case, where the type of
the exponent cannot be infered from other operands. Thus in many cases the
compiler has to choose a default type. It's just like I find
  (*) :: (Multiplyable a b c) => a -> b -> c
 not a good idea, say for various multiplications in linear algebra,
because of lost type inference.


More information about the Libraries mailing list