[Haskell-cafe] f^n for functional iteration

Danny Gratzer danny.gratzer at gmail.com
Fri Dec 13 15:04:38 UTC 2013


@Antonio, that defines sane instances for (a -> a), he needs [f ^ x] to be
[f . f . f . f . ....] which means that [f * f] is [f . f] not the [liftA2
(*)] that they use.


Cheers,
Danny Gratzer


On Fri, Dec 13, 2013 at 8:59 AM, Antonio Nikishaev <me at lelf.lu> wrote:

> Doug McIlroy <doug at cs.dartmouth.edu> writes:
>
> http://hackage.haskell.org/package/NumInstances
>
> > Agreeing with the analysis, I will sharpen my question.
> > Is option 2 possible at all, regardless of sanity concerns
> > (e.g. incomplete implementation of Num).
> >
> > Doug
> >
> >> On Tue, 10 Dec 2013 at 10:51 AM, Danny Gratzer <danny.gratzer at gmail.com>
> wrote
> >>
> >> Well (^) is already used for their traditional meaning and using this
> exact
> >> operator would require
> >>
> >>   1. Shadowing (^) from prelude
> >>   2. Making (a -> a) an instance of Num (impossible to do sanely)
> >>
> >> You can just use a different operator
> >>
> >>     f .^. n = foldl (.) id $ replicate n f
> >>
> >> On Tue, Dec 10, 2013 at 10:45 AM, Doug McIlroy <doug at cs.dartmouth.edu
> >wrote:
> >>
> >> > Is there a trick whereby the customary notation f^n for iterated
> >> > functional composition ((\n f -> foldl (.) id (replicate n f)) n f)
> can
> >> > be defined in Haskell?
> >> >
> >> > Doug McIlroy
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20131213/2d9718c8/attachment.html>


More information about the Haskell-Cafe mailing list