Hello everybody,
I checked the topics in Haskell-Cafe about prefix/infix operators but
I did not find them. Now I bring my questions to here to ask you.
1) I have a Common-Lisp code representing an expression result as follows
((MPLUS SIMP)
((MTIMES SIMP) ((RAT SIMP) 1 2) ((MEXPT SIMP) $X 2))
((MTIMES SIMP) ((RAT SIMP) 1 3) ((MEXPT SIMP) $X 3)))
2) I attempted to change it to mathematics operators, replacing
MPLUS SIMP -> +
MEQUAL SIMP -> =
RAT SIMP -> /
MEXPT SIMP -> ^
translate :: String -> String
translate [] = []
translate ('(':'M':'P':'L':'U':'S':' ':'S':'I':'M':'P':')':xs) = "(+)"
++ translate xs
translate ('(':'M':'T':'I':'M':'E':'S':' ' :'S':'I':'M':'P':')':xs) =
"(*)" ++ translate xs
translate ('(':'M':'E':'Q':'U':'A':'L':' ' :'S':'I':'M':'P':')':xs) =
"(=)" ++ translate xs
translate ('(':'R':'A':'T':' ':'S':'I':'M':'P':')':xs) = "(/)" ++ translate xs
translate ('(':'M':'L':'I':'S':'T':' ':'S':'I':'M':'P':')':xs) =
"([])" ++ translate xs
translate ('(':'M':'E':'X':'P':'T':' ':'S':'I':'M':'P':')':xs) = "(^)"
++ translate xs
translate ('$':'X':xs) = "x" ++ translate xs
translate ('$':'Y':xs) = "y" ++ translate xs
translate (x:xs) = x:translate xs
3) And NOW I want to transfer from prefix operator into infix
operator, for example: From
((+)
((*) ((/) 1 2) ((^) x 2))
((*) ((/) 1 3) ((^) x 3)))
in to the expression: 1/2*x^2+1/3*x^3
I try to figure out it, but this time it is not successfully. If you
are familiar with that, please share with me. Many thanks to all.
S.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe