[Haskell-cafe] Prolog-style list syntax?

Anthony Clayden anthony.d.clayden at gmail.com
Thu Jul 8 23:28:30 UTC 2021


Thanks Richard, see the discussion last month (same Subject line) that
considered/rejected various ideas

On Fri, 9 Jul 2021 at 00:05, Richard O'Keefe <raoknz at gmail.com> wrote:

> I note that
> (1) Clean uses ":" in lists the way Prolog uses "|".
>

Yeah that's where I started. [x : xs] is already valid Haskell, meaning [
(x: xs) ].


> (2) Before Prolog switched to "|", Edinburgh Prolog used ",.." (two
> tokens).
>

Haskell already has [1, 2 .. 5] for arithmetic sequences. `,..` Wouldn't
quite be ambiguous, but is dangerously close.

(3) There doesn't seem to be any reason why [p1,p2,p3]++pr could not be
> a pattern, where p1, p2, p3 match elements and pr  the rest.


Oh but `++` is an operator, not a constructor. Syntactically that's not a
pattern.
So [p1, p2]++pr++pq is a valid expression; what would it mean as a pattern?
Somebody in last month's discussion wanted similar, especially for strings
"prefix"++pr.
But it would be valid in a pattern only if the lhs were a pattern, and we
made a special syntactic case for ++. Then what if there's a user-defined
override for ++?

Also see my OP last month, I want the list to be the thing in [ ], not also
some trailing expression.


> Erlang has <string literal> ++ <pattern>, but forbids <list pattern> ++
> <pattern>,
> presumably because it uses "|" like Prolog.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210709/c94087f8/attachment.html>


More information about the Haskell-Cafe mailing list