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

 Macro names. type Macro = String | The arguments to beevaluated and passed to a macro. type Args = [Expr] | A

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!