[x] and (x:_) for lists -- did you ever think that odd?

Think back to when you first came across Haskell ... This, for example (from page 4 of the Gentle Intro -- my comments added): length :: [a] -> Integer -- [ ] means list length [] = 0 -- [] means list length (x: xs) = 1 + length xs -- list, but no [ ] Usually, showing a list uses square brackets and comma separators. So list literals use square brackets and comma separators. Type decls for a list uses square brackets. List builders use square brackets and commas -- such as [1, 3 .. 9] or [0 ..] Pattern matching for finite length lists use square brackets and commas: f [] = ... f [x] = ... f [x, y] = ... But pattern matching for unknown-length lists uses round brackets and colon -- such as that last binding for `length` above. And (nearly) every list-handling function has a pattern for unknown-length lists. Would this pattern matching seem less odd?: head [x ..] = x length [x, xs@..] = 1 + length xs Experienced Haskellers need not answer: you've got too used to ( : ) ;-) AntC

On Sun, May 20, 2012 at 5:14 PM, AntC
Would this pattern matching seem less odd?:
head [x ..] = x length [x, xs@..] = 1 + length xs
Experienced Haskellers need not answer: you've got too used to ( : ) ;-)
You missed experienced Lispers, who are likewise entirely comfortable with cons-like notation. I would want to very carefully check the implications of your suggestion: it might not integrate well with the rest of pattern matching syntax, in particular some uses of it might turn out to be impossible to distinguish from existing constructs. Some parts of Haskell's syntax are rather, how shall I put it? tightly reasoned, with less room for expansion than is immediately obvious. (Please note, I am not trying to say "don't bother", I am saying that the syntax questions really are tricky and you need to work carefully. This syntax might end up being fine, or it might need to be worked somewhat differently.) -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

Brandon Allbery
You missed experienced Lispers, who are likewise entirely comfortable with cons-like notation.
Good point Brandon, I should have asked what background and expectations people were coming from. From ALGOL, square brackets mean arrays, which are close-ish to lists(?) (For Lispers: does it seem odd using colon? Does it seem odd that dot is function composition, not cons pairing?) I was more getting at the oddness (or perhaps not) of having two different notations.
I would want to very carefully check the implications of your suggestion:
No, I wasn't anywhere near making a "suggestion" or "proposal". Just asking for people's impressions.
it might not integrate well with the rest of pattern matching syntax, ...
FWIW, the double-dot notation is not currently valid in a pattern. I wanted to show something with square brackets. And to my mind, the double- dot could be taken as an unknown-length tail of the list, like an ellipsis. But others (it seems) think of it as enumFrom. AntC

AntC
Would this pattern matching seem less odd?:
head [x ..] = x length [x, xs@..] = 1 + length xs
No, it seems and is more odd. Why hide the list constructors behind weird notation? Why require syntactic peculiarities and special cases for pattern-matching lists? In particular, what does pattern-matching against "enumFrom x" mean? Oh, it means something different here? Your proposed syntax is very arbitrary and helps to confuse everybody. Haskell has very simple syntactic rules, and I'm sure I'm speaking for most of the Haskell community when I say that we would like to keep it that way. We have access to the two list constructors (:) and [] directly and they are very convenient, so there is no need for weird syntax just to enforce a set of ASCII characters in source code.
Experienced Haskellers need not answer: you've got too used to ( : ) ;-)
Sorry, but this statement is very infantile. Even if meant as a joke, it's at best offensive and at worst insulting. There is good reasoning behind (:) and [], and just because you don't see it there is no reason to imply that experienced Haskell programmers are stubborn. Haskell programmers are about as open-minded as programmers can get. If you want people to take your proposals seriously, you shouldn't offend the very persons who evaluate them. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/

On May 20, 2012 7:59 PM, "Ertugrul Söylemez"
AntC
wrote: Would this pattern matching seem less odd?:
head [x ..] = x length [x, xs@..] = 1 + length xs
No, it seems and is more odd. Why hide the list constructors behind weird notation? Why require syntactic peculiarities and special cases for pattern-matching lists? In particular, what does pattern-matching against "enumFrom x" mean? Oh, it means something different here?
Your proposed syntax is very arbitrary and helps to confuse everybody. Haskell has very simple syntactic rules, and I'm sure I'm speaking for most of the Haskell community when I say that we would like to keep it that way. We have access to the two list constructors (:) and [] directly and they are very convenient, so there is no need for weird syntax just to enforce a set of ASCII characters in source code.
Experienced Haskellers need not answer: you've got too used to ( : ) ;-)
Sorry, but this statement is very infantile. Even if meant as a joke, it's at best offensive and at worst insulting. There is good reasoning behind (:) and [], and just because you don't see it there is no reason to imply that experienced Haskell programmers are stubborn. Haskell programmers are about as open-minded as programmers can get.
I think it was just a joke.
If you want people to take your proposals seriously, you shouldn't offend the very persons who evaluate them.
Greets, Ertugrul
-- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Tom Murphy
I think it was just a joke.
While a discussion is going on off the list, I would like to publicly
apologize for my rough tone. I felt offended by the last remark.
Of course I'm not taking back my statement, I just feel like it doesn't
really apply to Anthony's original post.
For questions like this I would recommend writing it in such a way that
the intention is clear. It was somehow blurred by the rhetorical style.
I also hope that people aren't offended by my mail signature, which
indeed is a bit offensive. =)
Greets,
Ertugrul
--
Key-ID: E5DD8D11 "Ertugrul Soeylemez

Ertugrul Söylemez
We have access to the two list constructors (:) and [] directly and they are very convenient,
So Ertugrul, as an experienced Haskeller which of these do you put in your code for a singleton list (whether appearing in a pattern or as an expression): [x] (x: []) Or perhaps you mix them, depending on whether you want to be more suggestive of an empty list [] or an unknown-length list (x: xs)? [.. snippety-snip] AntC

AntC
So Ertugrul, as an experienced Haskeller which of these do you put in your code for a singleton list (whether appearing in a pattern or as an expression): [x] (x: [])
I tend to use bracket notation for fixed-length list patterns.
Or perhaps you mix them, depending on whether you want to be more suggestive of an empty list [] or an unknown-length list (x: xs)?
Yes. It's quite seldom that I use bracket notation, though. That's simply because it's seldom that I pattern-match against fixed-length lists. Greets, Ertugrul
participants (4)
-
AntC
-
Brandon Allbery
-
Ertugrul Söylemez
-
Tom Murphy