Re: [Haskell-cafe] Showing the 1 element tuple

2006-12-22 Thread John Meacham
On Fri, Dec 22, 2006 at 11:13:50AM -0800, Dan Weston wrote:
> More generally, is there an operator version of dotted pair notation 
> (gasp, did I just lisp?) that works like:
> 
> data Tuple a b = () | Tuple a b
> 
> ()== ()
> ( ) 1 == Tuple 1 ()
> (2,'a',"hello") == Tuple 2 (Tuple 'a' (Tuple "hello" ()))
> 
> And is there anyway in Haskell to restrict the type definition above to 
> require that b be a type that can be constructed (possibly recursively) 
> with only () or Tuple, so the user doesn't do something stupid like 
> Tuple 1 'a', which is not a valid dotted pair?

HList seems similar to what you are going for:

http://homepages.cwi.nl/~ralf/HList/

John

-- 
John Meacham - ⑆repetae.net⑆john⑈
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Showing the 1 element tuple

2006-12-22 Thread Dan Weston
More generally, is there an operator version of dotted pair notation 
(gasp, did I just lisp?) that works like:


data Tuple a b = () | Tuple a b

()== ()
( ) 1 == Tuple 1 ()
(2,'a',"hello") == Tuple 2 (Tuple 'a' (Tuple "hello" ()))

And is there anyway in Haskell to restrict the type definition above to 
require that b be a type that can be constructed (possibly recursively) 
with only () or Tuple, so the user doesn't do something stupid like 
Tuple 1 'a', which is not a valid dotted pair?


Dan

John Meacham wrote:
have it be 
( ) 1


with a space between the parens to denote that it is a single tuple
rather than a nullary one.

John



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Showing the 1 element tuple

2006-12-20 Thread John Meacham
have it be 
( ) 1

with a space between the parens to denote that it is a single tuple
rather than a nullary one.

John
-- 
John Meacham - ⑆repetae.net⑆john⑈
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Showing the 1 element tuple

2006-12-20 Thread Henning Thielemann

On Tue, 19 Dec 2006, Neil Mitchell wrote:

> () -- 0 element tuple
> (,) a b -- 2 element tuple
> (,,) a b c -- 3 element tuple

The problem is that the separator approach (comma) doesn't scale well:
  http://haskell.org/haskellwiki/Terminator_vs._separator
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Showing the 1 element tuple

2006-12-19 Thread Marc A. Ziegert
> A weird question, what does the 1 element tuple look like?

there is one in Control.Monad.Identity:
 Identity 1
i miss the short version
 newtype Id x = x


writing (1,) is not that well defined; how do you want to use its constructor 
alone?
writing (1;) may be the solution, i think. (;) could be the constructor.
does anyone know, how ";" could cause any problems?
if i am not mistaken, (do return 1 ; return 2;) should be the same like ((do 
return 1 ; return 2);).

- marc


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Showing the 1 element tuple

2006-12-19 Thread Neil Mitchell

Hi


Python uses the syntax (foo,) to denote a singleton tuple (that is an extra
comma at the end); quoting the python tutorial "Ugly, but effective".


Yes, I thought of that, the issue is:

(a,b) is considered syntactic sugar for (,) a b
(a,) is syntactic sugar for...

And the place I'm displaying this is definately after desugaring!


Could tuples be implemented as an HList?
singleton = (`hCons` hNil)


Not in Yhc, no higher rank types :) Also tuples are really really
common, every class function has quite a few floating around - HList
is just too much overhead (I think).


Tuples represent dimensionality therefore a 1-element tuple is just a
1-dimensional value ie the value itself hence a == (a) == ((a)) == (((a)))


Tuples are a box you can put things in, in Haskell:

data Tuple a = Tuple a

Tuple (Tuple 1) /= 1

(either at runtime, at type time, or any other time)

Thanks

Neil
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Showing the 1 element tuple

2006-12-19 Thread Stefan O'Rear
On Tue, Dec 19, 2006 at 11:35:49PM -, Brian Hulley wrote:
> Tuples represent dimensionality therefore a 1-element tuple is just a 
> 1-dimensional value ie the value itself hence a == (a) == ((a)) == (((a))) 

That is true in a strict language, and for unboxed (unlifted) types, but in
haskell tuples are lifted types -- (a) contains _|_ and (_|_), while a only
contains _|_.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Showing the 1 element tuple

2006-12-19 Thread Brian Hulley

Neil Mitchell wrote:

Hi,

A weird question, what does the 1 element tuple look like?

() -- 0 element tuple
(,) a b -- 2 element tuple
(,,) a b c -- 3 element tuple

() a - meaningless
(a) - a in brackets

GHC has the 1 element unboxed tuple, (# a #), and all the other sizes
unboxed as well, but how would you visually represent the 1 element
boxed tuple?


Tuples represent dimensionality therefore a 1-element tuple is just a 
1-dimensional value ie the value itself hence a == (a) == ((a)) == (((a))) 
== ...


Brian.
--
http://www.metamilk.com 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Showing the 1 element tuple

2006-12-19 Thread Greg Fitzgerald

Neil,

On Tue, Dec 19, 2006 at 10:41:56PM +, Neil Mitchell wrote:

A weird question, what does the 1 element tuple look like?


Could tuples be implemented as an HList?

singleton = (`hCons` hNil)

-Greg
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Showing the 1 element tuple

2006-12-19 Thread dgriffi3

On Tue, Dec 19, 2006 at 10:41:56PM +, Neil Mitchell wrote:

Hi,

A weird question, what does the 1 element tuple look like?

() -- 0 element tuple
(,) a b -- 2 element tuple
(,,) a b c -- 3 element tuple

() a - meaningless
(a) - a in brackets

GHC has the 1 element unboxed tuple, (# a #), and all the other sizes
unboxed as well, but how would you visually represent the 1 element
boxed tuple?

As it happens, Yhc _does_ have the 1 element tuple, you just can't use
it from normal programs, its only created by desugarings of class
instances. I'd quite like to change this, and I also need to render
the 1 element tuple in some way, so wondered if anyone had any good
ideas (or if there is even some sort of convention)

I currently use ()1, but don't like that as it doesn't follow Haskell
rules - the () and 1 would be separate lexemes. My other thought is
(?), where ? is something appropriate - but all the appropriate things
I can think of would either not be a lexeme (i.e. 1), having an
existing meaning (i.e. . | etc) or seem wrong.

Thoughts?


Python seems to use (1,) which seems reasonably clear.

--
Dennis Griffith, [EMAIL PROTECTED] Treasurer
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Showing the 1 element tuple

2006-12-19 Thread Stefan O'Rear
On Tue, Dec 19, 2006 at 10:41:56PM +, Neil Mitchell wrote:
> A weird question, what does the 1 element tuple look like?
> 
> () -- 0 element tuple
> (,) a b -- 2 element tuple
> (,,) a b c -- 3 element tuple
> 
> () a - meaningless
> (a) - a in brackets
...
> Thoughts?

Python uses the syntax (foo,) to denote a singleton tuple (that is an extra
comma at the end); quoting the python tutorial "Ugly, but effective".
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Showing the 1 element tuple

2006-12-19 Thread Neil Mitchell

Hi,

A weird question, what does the 1 element tuple look like?

() -- 0 element tuple
(,) a b -- 2 element tuple
(,,) a b c -- 3 element tuple

() a - meaningless
(a) - a in brackets

GHC has the 1 element unboxed tuple, (# a #), and all the other sizes
unboxed as well, but how would you visually represent the 1 element
boxed tuple?

As it happens, Yhc _does_ have the 1 element tuple, you just can't use
it from normal programs, its only created by desugarings of class
instances. I'd quite like to change this, and I also need to render
the 1 element tuple in some way, so wondered if anyone had any good
ideas (or if there is even some sort of convention)

I currently use ()1, but don't like that as it doesn't follow Haskell
rules - the () and 1 would be separate lexemes. My other thought is
(?), where ? is something appropriate - but all the appropriate things
I can think of would either not be a lexeme (i.e. 1), having an
existing meaning (i.e. . | etc) or seem wrong.

Thoughts?

Neil
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe