[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 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 function :/ In terms o

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 (dropWhi

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).

Re: [Haskell-cafe] Applicative is like an Arrow

2013-08-17 Thread Mathijs Kwik
damodar kulkarni writes: > Thanks for this nice analogy and explanation. This brings "monad > transformers" to my mind. > "without" monad transformers, the monads are bit crippled in their > applicability (please correct me if I am wrong) > and > "with" monad transformers the code becomes to some

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, Chr

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 m...@joachim-

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

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

[Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Hartmut Pfarr
Hello, I've a problem connecting to my postgresql database. Can You help me fix the ambigious type signature? (The example is identical to the first 5-liner-example in the package documentation) http://hackage.haskell.org/packages/archive/postgresql-simple/0.3.5.0/doc/html/Database-PostgreSQL

Re: [Haskell-cafe] Applicative is like an Arrow

2013-08-17 Thread David Menendez
On Sat, Aug 17, 2013 at 8:23 AM, Mathijs Kwik wrote: > damodar kulkarni writes: > > > Thanks for this nice analogy and explanation. This brings "monad > > transformers" to my mind. > > "without" monad transformers, the monads are bit crippled in their > > applicability (please correct me if I am

Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Brandon Allbery
On Sat, Aug 17, 2013 at 1:35 PM, Hartmut Pfarr wrote: > (The example is identical to the first 5-liner-example in the package > documentation) > As I read it, the example has a typo: it should be using `query_` instead of `query`. See http://hackage.haskell.org/packages/archive/postgresql-simple/

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

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 -

Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Hartmut Pfarr
Thx, I changed now from query to query_ Now the coding is like that: {-# LANGUAGE OverloadedStrings #-} import Database.PostgreSQL.Simple import Database.PostgreSQL.Simple.FromRow hello :: (FromRow a) => IO [a] hello = do

Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Tom Ellis
On Sat, Aug 17, 2013 at 11:59:24PM +0200, Hartmut Pfarr wrote: > {-# LANGUAGE OverloadedStrings #-} > > import Database.PostgreSQL.Simple > import Database.PostgreSQL.Simple.FromRow > > hello :: (FromRow a) => IO [a] > hello = do > conn <- connect defaultConnectInfo > query_ conn "select 2 +

Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Brandon Allbery
On Sat, Aug 17, 2013 at 5:59 PM, Hartmut Pfarr wrote: > query_ conn "select 2 + 2" > > I've no errors any more. > But: I don't see any result (for sure, it is not coeded yet) > Yes, because you're not capturing it; it's the return value from `query_`, which you are throwing away above instead o

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

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

[Haskell-cafe] continuations and monads

2013-08-17 Thread Christopher Howard
Q: Are the "continuations" in Scheme related to the "monads" from Haskell? If so, could someone elaborate on that? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] continuations and monads

2013-08-17 Thread Tikhon Jelvis
Yes they are. Purely intuitively, you can see how writing code in a monadic style (using >>= a lot) is very similar to writing in continuation-passing style. You can express this the most directly with the continuation monad. Then, from this monad, you can express other monads. In some sense, the

Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Hartmut Pfarr
... thx all for helping. Now the coding works: it puts the following out. Kind regards Hartmut *Main> main Only {fromOnly = 4} -- Only {fromOnly = 101} Only {fromOnly = 102} Only {fromOnly = 103} -- blub 101 51 blub 102 52 blub 103 53 The

Re: [Haskell-cafe] Applicative is like an Arrow

2013-08-17 Thread damodar kulkarni
Thanks again for the detailed and explanatory answer. That's the reason I'm writing these huge responses, because I hope I can > shorten this journey for others. > This has certainly helped me grasp some aspects in this regard. While Monad Transformers are awesome and can solve many problems qui