Richard Eisenberg | 30 Aug 02:08 2013

ANN: th-desugar simplifies Template Haskell processing

I've just uploaded my new th-desugar package, which enables easier processing of Template Haskell source
syntax by desugaring it into a much simpler core language. The meaning of the code after desugaring is
identical to before desugaring, but the syntax is much simpler. To wit, th-desugar simplifies out all of
the following constructs:

- guarded expressions in both functions and case statements
- "where" declarations
- do syntax
- list/monad comprehensions
- record creation / updates
- as patterns
- non-trivial patterns in a lambda expression
- lambda-case
- multi-way if
- several more

If you are writing a library that manipulates Template Haskell syntax, you may wish to consider if
th-desugar will make your job easier by forcing you to consider fewer cases. The one source Haskell
construct supported by Template Haskell but not supported by th-desguar is view patterns, mostly
because these interact quite non-trivially with pattern binders. It's possible this hole will be closed
in a future version.

Enjoy!
Richard
Sjoerd Visscher | 31 Aug 18:06 2013

Re: ANN: th-desugar simplifies Template Haskell processing

Great package!

One question: Do you remove/inline type synonyms? I ask because I just ran into this with some TH code. I'm
looking for types that end with -> a, but that fails when type synonyms are involved.

Sjoerd

On Aug 30, 2013, at 2:08 AM, Richard Eisenberg <eir <at> cis.upenn.edu> wrote:

> I've just uploaded my new th-desugar package, which enables easier processing of Template Haskell
source syntax by desugaring it into a much simpler core language. The meaning of the code after desugaring
is identical to before desugaring, but the syntax is much simpler. To wit, th-desugar simplifies out all
of the following constructs:
> 
> - guarded expressions in both functions and case statements
> - "where" declarations
> - do syntax
> - list/monad comprehensions
> - record creation / updates
> - as patterns
> - non-trivial patterns in a lambda expression
> - lambda-case
> - multi-way if
> - several more
> 
> If you are writing a library that manipulates Template Haskell syntax, you may wish to consider if
th-desugar will make your job easier by forcing you to consider fewer cases. The one source Haskell
construct supported by Template Haskell but not supported by th-desguar is view patterns, mostly
because these interact quite non-trivially with pattern binders. It's possible this hole will be closed
in a future version.
(Continue reading)

Richard Eisenberg | 2 Sep 03:25 2013

Re: ANN: th-desugar simplifies Template Haskell processing

No, but I agree that this behavior is useful and in the spirit of th-desugar. I can add this to the next
version, which should come out in a few days (tomorrow?), because I've noticed a bug with the scoping of
as-patterns in let statements.

Thanks for the suggestion!
Richard

On Aug 31, 2013, at 12:06 PM, Sjoerd Visscher wrote:

> Great package!
> 
> One question: Do you remove/inline type synonyms? I ask because I just ran into this with some TH code. I'm
looking for types that end with -> a, but that fails when type synonyms are involved.
> 
> Sjoerd
> 
> On Aug 30, 2013, at 2:08 AM, Richard Eisenberg <eir <at> cis.upenn.edu> wrote:
> 
>> I've just uploaded my new th-desugar package, which enables easier processing of Template Haskell
source syntax by desugaring it into a much simpler core language. The meaning of the code after desugaring
is identical to before desugaring, but the syntax is much simpler. To wit, th-desugar simplifies out all
of the following constructs:
>> 
>> - guarded expressions in both functions and case statements
>> - "where" declarations
>> - do syntax
>> - list/monad comprehensions
>> - record creation / updates
>> - as patterns
>> - non-trivial patterns in a lambda expression
(Continue reading)

Anders Persson | 2 Sep 08:31 2013
Picon

Re: ANN: th-desugar simplifies Template Haskell processing

For expanding/inlining type synonyms, there is also th-expand-syns (http://hackage.haskell.org/package/th-expand-syns).

/Anders


On Mon, Sep 2, 2013 at 3:25 AM, Richard Eisenberg <eir <at> cis.upenn.edu> wrote:
No, but I agree that this behavior is useful and in the spirit of th-desugar. I can add this to the next version, which should come out in a few days (tomorrow?), because I've noticed a bug with the scoping of as-patterns in let statements.

Thanks for the suggestion!
Richard

On Aug 31, 2013, at 12:06 PM, Sjoerd Visscher wrote:

> Great package!
>
> One question: Do you remove/inline type synonyms? I ask because I just ran into this with some TH code. I'm looking for types that end with -> a, but that fails when type synonyms are involved.
>
> Sjoerd
>
> On Aug 30, 2013, at 2:08 AM, Richard Eisenberg <eir <at> cis.upenn.edu> wrote:
>
>> I've just uploaded my new th-desugar package, which enables easier processing of Template Haskell source syntax by desugaring it into a much simpler core language. The meaning of the code after desugaring is identical to before desugaring, but the syntax is much simpler. To wit, th-desugar simplifies out all of the following constructs:
>>
>> - guarded expressions in both functions and case statements
>> - "where" declarations
>> - do syntax
>> - list/monad comprehensions
>> - record creation / updates
>> - as patterns
>> - non-trivial patterns in a lambda expression
>> - lambda-case
>> - multi-way if
>> - several more
>>
>> If you are writing a library that manipulates Template Haskell syntax, you may wish to consider if th-desugar will make your job easier by forcing you to consider fewer cases. The one source Haskell construct supported by Template Haskell but not supported by th-desguar is view patterns, mostly because these interact quite non-trivially with pattern binders. It's possible this hole will be closed in a future version.
>>
>> Enjoy!
>> Richard
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe <at> haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane