[Haskell-cafe] Prolog-style list syntax?

Anthony Clayden anthony.d.clayden at gmail.com
Wed Jul 7 06:36:07 UTC 2021


Ok so I implemented both ideas:

>     elem2 _ []       = False
>    elem2 x [y,: ys] = x == y || elem2 x ys

>    let [x,y,z,w,: ws] = "hello there" in ws -- yields "o there"

In fact it was easier to implement both ideas than make a special case of
`(:)`. So these work

>    let [x,:+ xs] = [1,2,3,:+ Nily] in xs

> let [x,`ConsSet` xs] = [1,2,3,`ConsSet` NilSet] in xs

with decls

>    infixr 5 :+
>    data Listy a = Nily | a :+ (Listy a)  deriving (Eq, Show, Read)

>     infixr 5 `ConsSet`
>    data Set a = NilSet | ConsSet a (Set a)  deriving (Eq, Show, Read)


On Wed, 30 Jun 2021 at 19:00, Anthony Clayden <anthony.d.clayden at gmail.com>
wrote:

> Ok thank you for the feedback, I get the message not to re-purpose
> currently valid syntax.
>
>
> >    [x, y ,: ys ]           -- ? not currently valid
>
> We could make list syntax work harder
>
> >    [x, y ,:+ ys ]
>
> Means desugar the commas by applying constructor `:+` instead of `:`. That
> could be in general any constructor starting `:`.
>
> Or indeed could be a pattern synonym starting `:`, which is a 'smart
> constructor' to build the list maintaining some invariant.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210707/73f6d786/attachment.html>


More information about the Haskell-Cafe mailing list