[Haskell-cafe] f^n for functional iteration

Brandon Allbery allbery.b at gmail.com
Thu Dec 12 03:55:09 UTC 2013


On Wed, Dec 11, 2013 at 10:48 PM, Danny Gratzer <danny.gratzer at gmail.com>wrote:

> This seems to work
>
> {-# LANGUAGE FlexibleInstances #-}
> instance Num (a -> a) where
>   (*) = (.)
>
> Of course, using anything else from the Num class will blow up in your
> face so it's probably not worth it.
>

And the hidden danger is that Num is special cased such that the compiler
more or less has an open license to infer Num instances all over the place
(see: defaulting, and its interaction with the monomorphism restriction),
and as a result it will infer things you would never have imagined. In
other words, the price of this is that type inference is no longer reliable
and type errors will be reported incomprehensibly, depending on how
consistently you specify type signatures (that is, the more you have, the
more comprehensible the errors; but few people actually use type signatures
*everywhere* they can be specified).

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20131211/755b7daa/attachment.html>


More information about the Haskell-Cafe mailing list