
Hi Do you mind tell what is mean by the symbol $ in this piece of code? Thanks a lot.
mcompile :: Prog -> State Int Code mcompile (Assign n e) = return $ compileExpr e ++ [POP n] mcompile (If e p1 p2) = do cur <- fresh pp1 <- mcompile p1 pp2 <- mcompile p2 return $ (compileExpr e ++ (JUMPZ cur):pp1 ++ JUMP (cur+1):(LABEL cur):pp2 ++ [LABEL (cur+1)]) mcompile (While e p) = do cur <- fresh mp <- mcompile p return $ [LABEL cur] ++ compileExpr e ++ [JUMPZ (cur+1)] ++ mp ++ [JUMP cur,LABEL (cur+1)] -- View this message in context: http://www.nabble.com/symbol-%24-tf3701618.html#a10351407 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

Maverick,
Do you mind tell what is mean by the symbol $ in this piece of code? Thanks a lot.
It denotes function application: infixr 1 $ ($) :: (a -> b) -> a -> b f $ x = f x Note how its precedence and associativity is the opposite of that of 'regular' function application. The ($) is typically used to limit the number of parentheses needed in a piece of code: f (g (h x)) vs. f $ g $ h $ x There are other options though: (f . g . h) x f . g . h $ x HTH, Stefan

Thanks a lot for your help I got the idea of this symbol now. It will be great if you can help me this time as well, this time is the symbol @ Here is the code that i got
evalExpr :: Expr -> Mem -> (Bool,Expr) evalExpr (Val x) _ = (True,Val x) evalExpr (Var n) env = if isNothing (lookup n env) then (False,Var n) else (True,Val (envLookup n env)) evalExpr c@(App op e1 e2) e = let (b1,v1) = (evalExpr e1 e) (b2,v2) = (evalExpr e2 e) > in if b1 && b2 then (True,Val (eval c e)) else (False,App op v1 v2) Thanks once more
Best regard Maverick Stefan Holdermans wrote:
Maverick,
Do you mind tell what is mean by the symbol $ in this piece of code? Thanks a lot.
It denotes function application:
infixr 1 $
($) :: (a -> b) -> a -> b f $ x = f x
Note how its precedence and associativity is the opposite of that of 'regular' function application. The ($) is typically used to limit the number of parentheses needed in a piece of code:
f (g (h x)) vs. f $ g $ h $ x
There are other options though:
(f . g . h) x f . g . h $ x
HTH,
Stefan _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- View this message in context: http://www.nabble.com/symbol-%24-tf3701618.html#a10362633 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

(False,Var n) else (True,Val (envLookup n env)) evalExpr c@(App op e1 e2) e = let (b1,v1) = (evalExpr e1 e) (b2,v2) = (evalExpr e2 e) > in if b1 && b2 then (True,Val (eval c e)) else (False,App op v1 v2)
Allows you to refer to "App op e1 e2" as just "c" on the right hand side. (i.e., it's just an alias.)
participants (3)
-
Andrew Coppin
-
Maverick
-
Stefan Holdermans