putting the result of a function in `infix` declaration

Hi everyone, Consider the following code: -------------- import Prelude hiding ((+)) data Expr = Plus Expr Expr | Minus Expr Expr | Expr String deriving Show f :: Expr -> Int f (Plus _ _) = 1 f (Minus _ _) = 2 -- infix (f (Plus undefined undefined)) + -- (*) infix 6 + (+) :: Expr -> Expr -> Expr e1 + e2 = Plus e1 e2 main = do let a = Expr "a" let b = Expr "b" print $ a + b -------------- I would like to declare the infix precedence of (+) with a function (commented line (*)) instead of directly as above. Is there any means to do that? Do we need some kind of preprocessing machinery? How to do that in Haskell? In a more general way, let us suppose I have a Haskell library able to perform some calculations: how to use it in a pre-processing step, before compilation of the executable? It could be a function to compute symbolically roots of a polynomial of second degree to be used at runtime. We would put some placeholders in the code where the result of the pre- processing calculation would enter. Thanks in advance, TP

On Sun, Jun 23, 2013 at 6:36 AM, TP
In a more general way, let us suppose I have a Haskell library able to perform some calculations: how to use it in a pre-processing step, before compilation of the executable?
You are looking for Template Haskell. http://www.haskell.org/haskellwiki/Template_Haskell I'm not sure how up-to-date the wiki is, but it should give you the general idea. -Karl V.

Related to Karl's Template Haskell suggestion you could also have a look at
quasiquotation:
http://www.haskell.org/haskellwiki/Quasiquotation
The GHC documentation has an example of a expression quoter:
http://www.haskell.org/ghc/docs/latest/html/users_guide/template-haskell.htm...
On 23 June 2013 22:22, Karl Voelker
On Sun, Jun 23, 2013 at 6:36 AM, TP
wrote: In a more general way, let us suppose I have a Haskell library able to perform some calculations: how to use it in a pre-processing step, before compilation of the executable?
You are looking for Template Haskell.
http://www.haskell.org/haskellwiki/Template_Haskell
I'm not sure how up-to-date the wiki is, but it should give you the general idea.
-Karl V.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Karl Voelker
-
Roel van Dijk
-
TP