I'd definitely be against what you propose; as you pointed out it introduces a syntax ambiguity, which I think should be avoided where possible.

On Mon, 28 Jun 2021, 4:19 pm Anthony Clayden, <anthony.d.clayden@gmail.com> wrote:

One of the annoying (to me) inconsistencies with Haskell syntax is that `[  ]` means 'here comes a list'; but for the most common way to write a list, you can't use `[  ]`:

>    elem x []        = False
>    elem x ( y: ys ) = ...

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.

Neither `|` inside `[   ]` in a pattern nor a comma-list with `|` inside `[   ]` is valid H98 syntax, nor valid in GHC extensions AFAICT.

In an expression, `[ x | xs ]` could be taken as a list comprehension, which is I guess why Haskell didn't follow Prolog. I've come across another theorem-prover that follows Prolog style, except it uses `:` instead of `|` inside `[   ]`. Unfortunately ...

>    elem x [ y: ys ] = ...

Is valid syntax, where `:` is cons, so this is a nested list. I'm thinking that's relatively uncommon, and means the same as `[ ( y: ys ) ]`. 

Would anyone be violently pro or anti changing the meaning of `:` appearing at top level in `[   ]` to mean cons-tail?

AntC
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.