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

Ian Ross ian at skybluetrades.net
Sat Aug 17 12:02:31 CEST 2013


In J (a sort of dialect of APL), there's a thing called "under", written
"&.".  The expression "(f &. g) x" is equivalent to "(g^:_1) (f (g x))"
where "g^:_1" is J's "obverse" of g, which in cases where it exists is
usually the inverse of g (
http://www.jsoftware.com/help/dictionary/intro26.htm).  Abusing notation
with some weird mixture of Haskell and J, this means that "((+) &. log)"
multiplies numbers by taking logs, adding and exponentiating.  You "inv" is
"under" for cases where g == g^-1 (reverse being a good example).  In cases
where g /= g^-1, it's obviously a useful operation, but the case where g ==
g^-1 seems a bit specialised.  Can you think of any other useful cases than
g == reverse?  I guess "inv (1/) sum" is the harmonic mean, but that's
another special case.


On 17 August 2013 11:40, Mateusz Kowalczyk <fuuzetsu at fuuzetsu.co.uk> wrote:

> On 17/08/13 10:11, Christopher Done wrote:
> > Anyone ever needed this? Me and John Wiegley were discussing a decent
> > name for it, John suggested inv as in involution. E.g.
> First thing I thought was ‘inverse’…
> >
> > 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.
> >
> I do this a lot as well. Why not skip the ‘g’ all together and have ‘f .
> reverse . f’ if that's all we're doing? You could even call it fromEnd
> at that point and we end up with a rather intuitive ‘fromEnd (drop 10)’.
> Maybe even just have an operator.
> > 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.
> >
>
>
> Is this a proposal for addition to something or is it just general
> discussion?
>
>
> --
> Mateusz K.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


-- 
Ian Ross   Tel: +43(0)6804451378   ian at skybluetrades.net
www.skybluetrades.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130817/3dba5e48/attachment.htm>


More information about the Haskell-Cafe mailing list