Idiom Brackets, take 1

She’s got idiom brackets now. A parser example.


> import Parsley

> data Exp
>   = V Char
>   | Neg Exp
>   | Exp :+: Exp
>   deriving Show

> pExp :: P Char Exp
> pExp =
>   (| Neg {teq '-'} pExp
>    | {teq '('} pExp :+: {teq '+'} pExp {teq ')'}
>    | V (tok isAlpha)
>    |)

You can write a bunch of alternatives in (| .. | .. | .. |) each alternative is an application (possibly infix) whose function is taken as pure, and whose arguments are effectful. Additional noise, contributing effects but no values can be inserted with { .. ; .. }. I know, I’ve stolen record update syntax. Boo hoo.

More in a bit.

One Response to “Idiom Brackets, take 1”

  1. Conor says:

    It’s been observed that spotting the main actor in {teq ‘(’} pExp :+: {teq ‘+’} pExp {teq ‘)’} is a mite tricky. It’s perhaps injudicious to mix too much noise with infix ops. In this case, (:+:) {teq ‘(’} pExp {teq ‘+’} pExp {teq ‘)’} might be a little clearer.

Leave a Reply