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

2013-08-19 Thread Nikita Danilenko
Hi, as for the nomenclature - mathematically the pattern f^{-1} . g . f is sometimes called conjugation [1]. One (trivial) type of occurrence is data Foo a = Foo { unFoo :: a } deriving Show instance Functor Foo where fmap f = Foo . f . unFoo The under function from the lens library [2]

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

2013-08-17 Thread Christopher Done
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.

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

2013-08-17 Thread Ivan Lazar Miljenovic
On 17 August 2013 19:11, Christopher Done chrisd...@gmail.com wrote: Anyone ever needed this? Me and John Wiegley were discussing a decent name for it, John suggested inv as in involution. E.g. In terms of a decent name: as soon as I saw the subject, I thought you were somehow inverting a

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

2013-08-17 Thread Mateusz Kowalczyk
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

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

2013-08-17 Thread Ian Ross
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

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

2013-08-17 Thread Tom Ellis
On Sat, Aug 17, 2013 at 11:11:07AM +0200, 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. inv reverse (take 10) inv reverse (dropWhile isDigit) trim = inv reverse (dropWhile isSpace) .

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

2013-08-17 Thread Tobias Dammers
Note that at least for the dropWhile example, there is a specialized function, dropWhileEnd, which is most likely more efficient than reversing the list twice. On Aug 17, 2013 3:35 PM, Tom Ellis tom-lists-haskell-cafe-2...@jaguarpaw.co.uk wrote: On Sat, Aug 17, 2013 at 11:11:07AM +0200,

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

2013-08-17 Thread Joachim Breitner
Hi, Am Samstag, den 17.08.2013, 11:11 +0200 schrieb Christopher Done: inv reverse (take 10) if you want that fast and lazy, check out http://www.joachim-breitner.de/blog/archives/600-On-taking-the-last-n-elements-of-a-list.html Greetings, Joachim -- Joachim “nomeata” Breitner

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

2013-08-17 Thread Anton Nikishaev
Christopher Done chrisd...@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

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

2013-08-17 Thread Dan Burton
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

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

2013-08-17 Thread Dan Burton
The lens docs even have an example of another helper function, involuted for functions which are their own inverse. live involuted reverse %~ ('d':) lived inv f g = involuted f %~ g http://hackage.haskell.org/packages/archive/lens/3.9.0.2/doc/html/Control-Lens-Iso.html#v:involuted -- Dan

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

2013-08-17 Thread John Wiegley
Dan Burton danburton.em...@gmail.com writes: under reversed (take 10) ['a'.. 'z'] qrstuvwxyz Excellent, thanks! -- John Wiegley FP Complete Haskell tools, training and consulting http://fpcomplete.com johnw on #haskell/irc.freenode.net