flatten comma operator

In 'Real World Haskell' I found code like LiftA2 (,) .... Looks odd. But after some experimenting in winghci I found that (,) 1 2 is valid code and is equal to (1,2). Now I wonder how to create (1,2,3). I think you need a join or a flatten function or ...? Join doesn't work? Kees

If (,) is a function that takes two elements and returns the 2-tuple, have you considered something like (,,)? :) On Wednesday, 6 June 2012 at 4:33 PM, Kees Bleijenberg wrote:
In 'Real World Haskell' I found code like LiftA2 (,) .... Looks odd. But after some experimenting in winghci I found that (,) 1 2 is valid code and is equal to (1,2). Now I wonder how to create (1,2,3). I think you need a join or a flatten function or ...? Join doesn't work?
Kees
_______________________________________________ Beginners mailing list Beginners@haskell.org (mailto:Beginners@haskell.org) http://www.haskell.org/mailman/listinfo/beginners

By the way, is the excerpt from RWH involving liftA2 the chapter on using Parsec? If so, this may be the code snippet you refer to: -- file: ch16/FormApp.hs a_pair :: CharParser () (String, Maybe String) a_pair = liftA2 (,) (many1 a_char) (optionMaybe (char '=' *> many a_char)) In this case, liftA2 is promoting the (,) operation to work with the two operations in the CharParser applicative functor. (,) is of type "a -> b -> (a,b)", so without lifting, we'd end up with something like "(CharParser () String, CharParser () Maybe String)" (just a guess here). liftA2 produces a new applicative functor action which computes each of (many1 a_char) and (optionMaybe (char '=' *> many a_char)), then gives the pure results to (,). On Wednesday, 6 June 2012 at 4:36 PM, Arlen Cuss wrote:
If (,) is a function that takes two elements and returns the 2-tuple, have you considered something like (,,)? :)
On Wednesday, 6 June 2012 at 4:33 PM, Kees Bleijenberg wrote:
In 'Real World Haskell' I found code like LiftA2 (,) .... Looks odd. But after some experimenting in winghci I found that (,) 1 2 is valid code and is equal to (1,2). Now I wonder how to create (1,2,3). I think you need a join or a flatten function or ...? Join doesn't work?
Kees
_______________________________________________ Beginners mailing list Beginners@haskell.org (mailto:Beginners@haskell.org) http://www.haskell.org/mailman/listinfo/beginners

This is indeed the code I was talking about. I did not understand how I could create (1,2,3) with the comma operator (,)((,) 1 2) 3 = ((1,2),3) and not (1,2,3). That's why I thought I needed a kind of join operation to 'flatten' this. Indeed (,,) 1 2 3 is (1,2,3). But I do not understand what is happening. Is (,,) predefined? Probably not. -----Oorspronkelijk bericht----- Van: Arlen Cuss [mailto:a@unnali.com] Verzonden: woensdag 6 juni 2012 8:43 Aan: Kees Bleijenberg CC: beginners@haskell.org Onderwerp: Re: [Haskell-beginners] flatten comma operator By the way, is the excerpt from RWH involving liftA2 the chapter on using Parsec? If so, this may be the code snippet you refer to: -- file: ch16/FormApp.hs a_pair :: CharParser () (String, Maybe String) a_pair = liftA2 (,) (many1 a_char) (optionMaybe (char '=' *> many a_char)) In this case, liftA2 is promoting the (,) operation to work with the two operations in the CharParser applicative functor. (,) is of type "a -> b -> (a,b)", so without lifting, we'd end up with something like "(CharParser () String, CharParser () Maybe String)" (just a guess here). liftA2 produces a new applicative functor action which computes each of (many1 a_char) and (optionMaybe (char '=' *> many a_char)), then gives the pure results to (,). On Wednesday, 6 June 2012 at 4:36 PM, Arlen Cuss wrote:
If (,) is a function that takes two elements and returns the 2-tuple, have you considered something like (,,)? :)
On Wednesday, 6 June 2012 at 4:33 PM, Kees Bleijenberg wrote:
In 'Real World Haskell' I found code like LiftA2 (,) .... Looks odd. But after some experimenting in winghci I found that (,) 1 2 is valid code and is equal to (1,2). Now I wonder how to create (1,2,3). I think you need a join or a flatten function or ...? Join doesn't work?
Kees
_______________________________________________ Beginners mailing list Beginners@haskell.org (mailto:Beginners@haskell.org) http://www.haskell.org/mailman/listinfo/beginners

On Wed, Jun 06, 2012 at 09:46:58AM +0200, Kees Bleijenberg wrote:
This is indeed the code I was talking about. I did not understand how I could create (1,2,3) with the comma operator (,)((,) 1 2) 3 = ((1,2),3) and not (1,2,3). That's why I thought I needed a kind of join operation to 'flatten' this.
It's not possible to create a triple using only the (,) operator -- there's no way to do the join/flatten operation you have in mind, because there's no valid type it could be assigned (unless you make it specific to three-tuples, but I'm guessing you have something more general in mind).
Indeed (,,) 1 2 3 is (1,2,3). But I do not understand what is happening. Is (,,) predefined? Probably not.
Yes, it is! -Brent

On Wednesday, 6 June 2012 at 5:46 PM, Kees Bleijenberg wrote:
This is indeed the code I was talking about. I did not understand how I could create (1,2,3) with the comma operator (,)((,) 1 2) 3 = ((1,2),3) and not (1,2,3). That's why I thought I needed a kind of join operation to 'flatten' this.
As Brent pointed out, you can't without making it very specific. Each length of tuple with its combination of types is a unique type itself; compare to a list, where [a] is the type for a list of any length (including zero) containing elements of type a. A list is trivial to append to, whereas tuples are not designed for "extension" in this manner, per se.
Indeed (,,) 1 2 3 is (1,2,3). But I do not understand what is happening. Is (,,) predefined? Probably not.
And as Brent pointed out also, it is. :) By the way, so is (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,)! I suspect GHC allows any number. The Haskell Report section 6.1.4 [1] says implementations must support up to at least 15. Cheers, Arlen [1] http://www.haskell.org/onlinereport/basic.html
-----Oorspronkelijk bericht----- Van: Arlen Cuss [mailto:a@unnali.com] Verzonden: woensdag 6 juni 2012 8:43 Aan: Kees Bleijenberg CC: beginners@haskell.org (mailto:beginners@haskell.org) Onderwerp: Re: [Haskell-beginners] flatten comma operator
By the way, is the excerpt from RWH involving liftA2 the chapter on using Parsec? If so, this may be the code snippet you refer to:
-- file: ch16/FormApp.hs a_pair :: CharParser () (String, Maybe String) a_pair = liftA2 (,) (many1 a_char) (optionMaybe (char '=' *> many a_char))
In this case, liftA2 is promoting the (,) operation to work with the two operations in the CharParser applicative functor.
(,) is of type "a -> b -> (a,b)", so without lifting, we'd end up with something like "(CharParser () String, CharParser () Maybe String)" (just a guess here).
liftA2 produces a new applicative functor action which computes each of (many1 a_char) and (optionMaybe (char '=' *> many a_char)), then gives the pure results to (,).
On Wednesday, 6 June 2012 at 4:36 PM, Arlen Cuss wrote:
If (,) is a function that takes two elements and returns the 2-tuple, have you considered something like (,,)? :)
On Wednesday, 6 June 2012 at 4:33 PM, Kees Bleijenberg wrote:
In 'Real World Haskell' I found code like LiftA2 (,) .... Looks odd. But after some experimenting in winghci I found that (,) 1 2
is valid code and is equal to (1,2).
Now I wonder how to create (1,2,3). I think you need a join or a flatten
function or ...? Join doesn't work?
Kees
_______________________________________________ Beginners mailing list Beginners@haskell.org (mailto:Beginners@haskell.org) http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org (mailto:Beginners@haskell.org) http://www.haskell.org/mailman/listinfo/beginners

On Wed, Jun 6, 2012 at 7:06 AM, Arlen Cuss wrote:
And as Brent pointed out also, it is. :) By the way, so is (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,)! I suspect GHC allows any number. The
Maybe not any number; more than 127 elements in a tuple used to cause core dumps.... -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

Hmm. I've tested over 6,432 to work, but I'm not sure this has any point any more … ;-) On Thursday, 7 June 2012 at 7:17 AM, Brandon Allbery wrote:
On Wed, Jun 6, 2012 at 7:06 AM, Arlen Cuss wrote:
And as Brent pointed out also, it is. :) By the way, so is (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,)! I suspect GHC allows any number. The
Maybe not any number; more than 127 elements in a tuple used to cause core dumps....
-- brandon s allbery allbery.b@gmail.com (mailto:allbery.b@gmail.com) wandering unix systems administrator (available) (412) 475-9364 vm/sms
participants (4)
-
Arlen Cuss
-
Brandon Allbery
-
Brent Yorgey
-
Kees Bleijenberg