Question: Macro names. type Macro = String | The arguments to be evaluated and passed to a macro. type Args = [Expr] | A sequence of

![evaluated and passed to a macro. type Args = [Expr] | A](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/10/6703fe504e3b8_9596703fe4fe1a1c.jpg)
Macro names. type Macro = String | The arguments to be evaluated and passed to a macro. type Args = [Expr] | A sequence of commands. type Block = [Cmd] | The mode of the pen. data Mode = Down | Up deriving (Eq,Show) | Commands. data Cmd CmdTODO -- This is a dummy constructor that should be removed! deriving (Eq,Show) | Pretty print a command. >>> prettyCmd (Pen Down) "pen down" >>> prettyCmd (Move (Lit 2) (Add (Ref "x") (Lit 3))) "move(2, x + 3)" >>> prettyCmd (Call "foo" [Lit 2, (Mul (Ref "x") (Lit 3))]) "foo(2, x * 3)". >>> prettyCmd (For "i" (Lit 1) (Lit 10) []) "for i = 1 to 10 {}" prettyCmd :: Cmd -> String prettyCmd = undefined | Pretty print a block of commands. >>> prettyBlock [] "{}" >>> putStrln (prettyBlock [Pen Up, Move (Lit 2) (Lit 3), Pen Down]) { pen up; move(2, 3); pen down } prettyBlock :: Block -> String prettyBlock [] = "{}" special case for empty blocks prettyBlock cs "{ ++ indent (prettyCmds cs) ++ " }" where indent = concatMap (\c -> if c ' ' then " else [c]) prettyCmds = intercalate "; " map prettyCmd 11 Macro names. type Macro = String | The arguments to be evaluated and passed to a macro. type Args = [Expr] | A sequence of commands. type Block = [Cmd] | The mode of the pen. data Mode = Down | Up deriving (Eq,Show) | Commands. data Cmd CmdTODO -- This is a dummy constructor that should be removed! deriving (Eq,Show) | Pretty print a command. >>> prettyCmd (Pen Down) "pen down" >>> prettyCmd (Move (Lit 2) (Add (Ref "x") (Lit 3))) "move(2, x + 3)" >>> prettyCmd (Call "foo" [Lit 2, (Mul (Ref "x") (Lit 3))]) "foo(2, x * 3)". >>> prettyCmd (For "i" (Lit 1) (Lit 10) []) "for i = 1 to 10 {}" prettyCmd :: Cmd -> String prettyCmd = undefined | Pretty print a block of commands. >>> prettyBlock [] "{}" >>> putStrln (prettyBlock [Pen Up, Move (Lit 2) (Lit 3), Pen Down]) { pen up; move(2, 3); pen down } prettyBlock :: Block -> String prettyBlock [] = "{}" special case for empty blocks prettyBlock cs "{ ++ indent (prettyCmds cs) ++ " }" where indent = concatMap (\c -> if c ' ' then " else [c]) prettyCmds = intercalate "; " map prettyCmd 11
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
