[Haskell-cafe] inv f g = f . g . f

Dan Burton danburton.email at gmail.com
Sat Aug 17 22:43:00 CEST 2013


This is indeed a job for lens, particularly, the Iso type, and the "under"
function. Lens conveniently comes with a typeclassed isomorphism called
"reversed", which of course has a list instance.

>>> under reversed (take 10) ['a'.. 'z']
"qrstuvwxyz"

-- Dan Burton
On Aug 17, 2013 10:23 AM, "Anton Nikishaev" <me at lelf.lu> wrote:

> Christopher Done <chrisdone at gmail.com> writes:
>
> > Anyone ever needed this? Me and John Wiegley were discussing a decent
> > name for it, John suggested inv as in involution. E.g.
> >
> > inv reverse (take 10)
> > inv reverse (dropWhile isDigit)
> > trim = inv reverse (dropWhile isSpace) . dropWhile isSpace
> >
> > That seems to be the only use-case I've ever come across.
>
> And it's here only because reverse^-1 ≡ reverse, is not it?
> I only can see how f ∘ g ∘ f^-1 can be a pattern.
>
> > There's also this one:
> >
> > co f g = f g . g
> >
> > which means you can write
> >
> > trim = co (inv reverse) (dropWhile isSpace)
> >
> > but that's optimizing an ever rarer use-case.
>
>
> --
> lelf
>
>
>
> _______________________________________________
> 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/20130817/4a8eaeb8/attachment.htm>


More information about the Haskell-Cafe mailing list