|
![](/i/fill.gif) |
On 17/10/2015 02:09 PM, Orchid Win7 v1 wrote:
> I've been a Haskell programmer for [at least] 10 years, and I've never
> seen *anybody* do this!
In other news:
let (,) x y = (5, 6)
This is legal. Bizarre, but true!
Suppose you have a 3-argument constructor:
data Fubar = Three Char Char Char
Now you can write something like
Three 'J' 'F' 'K'
which creates a Fubar value. But if you write just Three by itself, you
have a 3-argument function. As you'd expect.
You can create a 3-argument tuple like this:
(True, "Red", foo)
Weirdly, if you write
(,,)
this is a 3-argument function that constructs a 3-tuple. (Count the
commas carefully; notice how a *three* tuple has *two* commas in it!)
This is a fairly obscure language feature; it's mostly useful when you
want to quickly pass a tupling function as an argument to something:
zip = zipWith (,)
However, strictly speaking, that means it's legal to write
(,,) True "Red" foo
which is exactly the same as (True, "Red", foo), but with weirder syntax.
I had no idea that this is also legal *pattern* syntax! I can't imagine
why the heck you'd ever want to write it this way in a pattern. But it's
legal. So there.
Post a reply to this message
|
![](/i/fill.gif) |