Generating arithmetic expressions in TH

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Generating arithmetic expressions in TH

Vitor Rodrigues-2
Hello,

I am starting using TH to generate lambda expressions representing
arithmetic expressions.
My current problem is to generate code where all the lambda
abstractions are in the top level.
For example,

I would like to have

\x -> 1 + x

instead of

1 + (\x -> x)

My problem is that I  don't know in beforehand if the second operand
is a variable or not.
If so, I would like to build a top level abstraction.

It is this possible?

Regards,
Vitor
_______________________________________________
template-haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/template-haskell
Reply | Threaded
Open this post in threaded view
|

Re: Generating arithmetic expressions in TH

Ahn, Ki Yung
Vitor Rodrigues wrote:

> Hello,
>
> I am starting using TH to generate lambda expressions representing
> arithmetic expressions.
> My current problem is to generate code where all the lambda
> abstractions are in the top level.
> For example,
>
> I would like to have
>
> \x -> 1 + x
>
> instead of
>
> 1 + (\x -> x)

This is a type error (unless you have declared some special instance of
Num to make that work), so you can't generate this with TH.  It will
fail to type check when splicing or when type checking quasiquotes.

> My problem is that I  don't know in beforehand if the second operand
> is a variable or not.
> If so, I would like to build a top level abstraction.
>
> It is this possible?
>
> Regards,
> Vitor

_______________________________________________
template-haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/template-haskell