[Haskell-cafe] RFC: revisiting the simplified haskell-src-exts AST

Matthew Pickering matthewtpickering at gmail.com
Sun Jul 31 11:45:23 UTC 2016


Hello Bertram,

This is a good idea.

I also considered this but to provide a proper compatibility layer it is
necessary to "bundle" pattern synonyms with suitable type constructors so
that when users import the type constructor then they also import the
suitable pattern synonyms.

This feature was only implemented in GHC 8.0. It is currently not much
effort to maintain HSE to support back to at least GHC 7.4 so it didn't
seem worth sacrificing this.

It would be good to provide this shim in future versions of the library but
at the moment the feature isn't mature enough. Message me when you release
this to Hackage and I will add a link to the README.

Matt

On Sat, Jul 30, 2016 at 11:22 PM, Bertram Felgenhauer via Haskell-Cafe <
haskell-cafe at haskell.org> wrote:
> 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(-)
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160731/7ab3374a/attachment.html>


More information about the Haskell-Cafe mailing list