[Haskell-cafe] putting the result of a function in `infix` declaration
TP
paratribulations at free.fr
Sun Jun 23 15:36:45 CEST 2013
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
More information about the Haskell-Cafe
mailing list