[Haskell-cafe] Prolog-style list syntax?

Jeff Clites jclites at mac.com
Tue Jun 29 05:57:16 UTC 2021


> On Jun 28, 2021, at 11:15 AM, Viktor Dukhovni <ietf-dane at dukhovni.org> wrote:
> 
> On Mon, Jun 28, 2021 at 11:04:46AM -0700, Jeff Clites via Haskell-Cafe wrote:
> 
>>> how so?  `x : y : z : zs`
>> 
>> I don’t mind the existing either, but it would be interesting if this worked:
>> 
>>    [x, y, z] ++ zs = list
> 
> It is far from clear why this or any similar pattern would be more
> ergonomic than:
> 
>    x : y : z : zs

The thread started with:

> 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 ) = ...

I sympathize with that observation, that there’s a special syntax for constructing lists, but you can’t use a similar syntax for the most common pattern-matching case (you can only use it for matching all elements of the list), and the special syntax is a nice visual signal that you are working with lists.

It’s not that x : y : z : zs is bad, it’s just not as distinctive. Someone thought it was worth inventing [a, b, c] even though you could just have written a : b : c : Nil, so similar motivations apply.

Something like this might work:

    [x, y, z, zs*] = list

But I actually like this the best:

    [x, y, z, zs...] = list

(The overlap with existing range syntax might actually be beneficial.)

Jeff


More information about the Haskell-Cafe mailing list