[Haskell-cafe] Let's teach GHC idiom brackets!

Christopher Done chrisdone at gmail.com
Thu Feb 19 10:54:53 UTC 2015

On 19 February 2015 at 10:56, Oliver Charles <ollie at ocharles.org.uk> wrote:
> This is something I think is very important - I often nest applicative
> syntax in my own code, and it's essential to me that I would be able to
> nest idiom brackets too.

Indeed, it definitely adds to the handiness to nest them.

> My current solution for dealing with sums is to use asum:

> asum [[i|TopicalizedSentenceExistential existentialTopic
>                                         (optional (try sentenceCoord))
>      ,[i|TopicalizedSentenceUniversal universalTopic sentenceCoord |]
>      ,[i|TopicalizedSentenceComposite compositeSentence|]]

> Though it is a little noisy, I think it gives you want you want -
> machine-predictable indentation and consistency.

As mentioned via IRC, this is tricky due to the unclear semantic
differences between x <|> y and asum [x,y] (i.e. the implicit “empty” in
asum). asum1 is a solution, but partial functions like that trouble

Generally I'd prefer to just use asum or asum1, though.

>   personBirthdayProduct = proc () -> do
>     personRow   <- personQuery -< ()
>     birthdayRow <- birthdayQuery -< ()
>     returnA -< (personRow, birthdayRow)

> right now becomes

>      (,) <$> personQuery <*> birthdayQuery
>   or liftA2 (,) personQuery birthdayQuery

> but with idiom brackets becomes

>   (| (personQuery, birthdayRow) |)

Right, in the case that you don't want to name anything the idiom is
much cleaner.

More information about the Haskell-Cafe mailing list