Idiom brackets via source plugin

Posted on 2018-07-06 by Oleg Grenrus

Today I experimented with upcoming GHC-8.6 feature: Source Plugins. In GHC 8.6 plugin functionality is extended, so there are more hooks where we can add own processing of the AST: after parsing, renaming or type-checking. For idiom brackets we'll change the AST right after the parsing step.

Idiom brackets (introduced in Applicative programming with effects paper) is a syntax extension to write Applicative expressions without drowning into <*>. The Strathclyde Haskell Enhancement also supports idiom brackets, but with different syntax. The point my plugin tries to solve: a lot of preprocessors can be built using GHC for the boring parts (like parsing).

As nobody (?) writes their lists as ([1, 2, 3]), we can steal that syntax! (Note: I don't know how to ignore, or lift pure values, ideas welcome)

#Implementation

The implementation is on GitHub: https://github.com/phadej/idioms-plugins

It's not complicated, little over hundred lines right now. Some highlights:

I invite you to look through the implementation, think about what else Source Plugins can be used for, and implementing those ideas!

Please ask me questions (e.g. on twitter I'm @phadej), if I cannot answer them myself, I'll find someone who can!

Site proudly generated by Hakyll