Enhanced type guard syntax]

Chris Pressey cpressey@REDACTED
Mon Sep 22 16:54:58 CEST 2003

On Mon, 22 Sep 2003 18:13:08 +1200 (NZST)
"Richard A. O'Keefe" <ok@REDACTED> wrote:

> Concerning the examples:
> 	foo(X == 2 * Y)
> 		% foo(X, Y) when X == 2*Y
> 	foo(X > Y)
> 		% foo(X, Y) when X > Y
> am I the only one who is bothered (to put it politely) that the
> "improved" versions _look_ as if they have one argument, but are
> supposedly equivalent to functions with _two_ arguments, and that
> there's no obvious way to tell which argument is which?

No, it also seemed to bother Klacke very much :)

But what could be a more obvious way to tell which argument is which,
than their order?  in "X > Y", X appears first, so it's the first

> For some reason, Haskell programmers don't seem to might writing
> 	foo x y | x == 2*y =
> 	...
> 	foo x y | x < y    =
> 	...
> "Chris" wrote:
> 	I also don't think it's any more difficult to read, once you
> 	unlearn the arbitrary convention that "comma seperates
> 	arguments".
> It may be arbitrary, but so are all human communication conventions,
> and this one has been going strong in programming languages for 50
> years."As a language design idea in its own right", I very much
> dislike a notation where I can't tell which argument is which.

Stick-in-the-mud!  You're just jealous 'cuz I'm an "early adopter." :)

Seriously, you have every right to dislike it as much or as little as
you like since aesthetics are subjective and it's just another
variation on notation.  (That's probably the main reason people cringe
at Forth and Lisp code too, it's "impossible to read" (until you learn
to read it :))

But I don't think you can show that this notation is not more concise. 
Which, I believe, was the main thrust of the original thread (that
A/integer is more concise than (A) when is_integer(A).)

> Now let's consider
>     f([X|_], [Y|_]) when X < Y -> ...
> how do you write _that_ without commas?

You don't, because I didn't say "never use commas," I said "commas
become 'and's" (or something very close to 'and')  You write it like

  f([X | _], [Y | _], X < Y) ->


More information about the erlang-questions mailing list