[Haskell-cafe] RFC: revisiting the simplified haskell-src-exts AST
Bertram Felgenhauer
bertram.felgenhauer at googlemail.com
Sat Jul 30 22:22:19 UTC 2016
Dear all,
the latest major release of haskell-src-exts (version 1.18) removed
the annotation free variant of the Haskell AST. It occurred to me that
using ghc's pattern synonyms it is possible to offer a light-weight
simplified view on the annotated AST. For example,
Language.Haskell.Exts.Syntax defines
data Name l = Ident l String | Symbol l String
and we can provide a simplified view with all annotations equal to ()
by doing
{-# LANGUAGE PatternSynonyms #-}
import qualified Language.Haskell.Exts.Syntax as H
type Name = H.Name ()
pattern Ident a = H.Ident () a
pattern Symbol a = H.Symbol () a
Because the type isn't changed, no code has to be reimplemented to
work with this AST.
A first rough cut at an implementation can be found on github [1].
Before releasing it on hackage (which requires some more polishing)
I'd appreciate feedback on the approach. Would you consider using
such a package? Is there a better approach? Also any thoughts on
usability (e.g., how to approach documentation) would be welcome.
Cheers, Bertram
[1] https://github.com/int-e/haskell-src-exts-simple
P.S. This grew out of an effort to update lambdabot to HSE-1.18,
which made me feel awful about all the superfluous and ugly () in
the resulting code. I also have some numbers showing that the
annotation-free view makes updating the code smoother:
Using the annotation-free view, the update touches 75 lines:
src/Lambdabot/Plugin/Haskell/Eval.hs | 18 +-
src/Lambdabot/Plugin/Haskell/Pointful.hs | 201 +++++++++++++++----------------
src/Lambdabot/Plugin/Haskell/Pretty.hs | 14 +-
src/Lambdabot/Plugin/Haskell/UnMtl.hs | 62 ++++-----
src/Lambdabot/Plugin/Haskell/Undo.hs | 115 ++++++++---------
5 files changed, 72 insertions(+), 75 deletions(-)
Using the haskell-src-exts 1.18 AST, the update touches 208 lines:
src/Lambdabot/Plugin/Haskell/Pointful.hs | 87 ++++++++++++++-----------------
src/Lambdabot/Plugin/Haskell/Pretty.hs | 12 ++--
src/Lambdabot/Plugin/Haskell/UnMtl.hs | 10 +--
src/Lambdabot/Plugin/Haskell/Undo.hs | 34 ++++++------
5 files changed, 204 insertions(+), 206 deletions(-)
More information about the Haskell-Cafe
mailing list