[Haskell-cafe] Prolog-style list syntax?

Albert Y. C. Lai trebla at vex.net
Mon Jun 28 16:06:39 UTC 2021


On 2021-06-28 2:17 a.m., Anthony Clayden wrote:
> Prolog syntax has lists, signalled by `[   ]`: [], [1], [2, 3], [4, 5, 
> 6], [[7, 8], [9, 10, 11]] are all valid list literals. For cons it also 
> uses `[   ]` syntax
> 
>  >    elem x [y | ys ] = ...
> 
> `[ x, y, z | zs ]` is also valid; pattern match or build a list with at 
> least 3 elements, where `zs` is the tail -- 4th element onwards (if 
> any). That structure is particularly ugly in Haskell syntax.

Prolog list syntax is the annoying one to me because it is watered down 
Hungarian notation again but with symbols instead of letters.  "If it's 
a string, prefix with sz; if it's a list, surround with []".

The logical conclusion of "elem : list" is

e1 : e2 : e3 : e4 : list

without needing a 2nd notation to make it nicer.

The logical conclusion of "[elem | list]" is

[e1 | [e2 | [e3 | [e4 | list]]]]

That's not nice. That explains why someone had to invent a 2nd notation, 
[e1, e2, e3, e4 | list].  Ironically, the need for a 2nd notation proves 
that the original "[elem | list]" design was ill-conceived.



More information about the Haskell-Cafe mailing list