Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
pp:l04xx [2020/03/20 21:33]
pdmatei
pp:l04xx [2020/04/07 15:11] (current)
pdmatei
Line 1: Line 1:
-======= Programming with ADTs =======+======= ​6. Programming with ADTs =======
  
 1. A **dictionary** is a collection of key-value pairs, which we can represent in Haskell as a list of pairs ''​(String,​Integer)''​ where ''​String''​ is the key type and ''​Integer''​ is the value type: 1. A **dictionary** is a collection of key-value pairs, which we can represent in Haskell as a list of pairs ''​(String,​Integer)''​ where ''​String''​ is the key type and ''​Integer''​ is the value type:
Line 25: Line 25:
 </​code>​ </​code>​
  
-4. Implement a function which takes a dictionary of program variables, a program expression ''​PExpr'',​ and evaluates it. For instance: ''​eval_pexpr [("​x",​2),​("​y",​1)] ((Var "​x"​) :+: (Var "​y"​))''​ returns 3.+4. Implement a function which takes a dictionary of program variables, a program expression ''​PExpr'',​ and evaluates it. For instance: ''​eval_pexpr [("​x",​2),​("​y",​1)] ( (Var "​x"​) :+: (Var "​y"​) )''​ returns 3.
 <code haskell> <code haskell>
 eval_pexpr :: Dict -> PExpr -> Integer eval_pexpr :: Dict -> PExpr -> Integer
Line 61: Line 61:
             Begin Prog Prog |     -- <p> <​p'>​             Begin Prog Prog |     -- <p> <​p'>​
             While BExpr Prog |     -- while (<​expr>​) { <p> }             While BExpr Prog |     -- while (<​expr>​) { <p> }
-            If BExpr Prog Prog      -- if (<​expr>​) { <p> } else { <​p'>​ }  +            If BExpr Prog Prog      -- if (<​expr>​) { <p> } else { <​p'>​ }   ​
-       +
-            -- deriving Show  ​+
  
--- ex7: modify show_p so that program and boolean expressions are also displayed 
 show_p :: Prog -> String show_p :: Prog -> String
 show_p (PlusPlus v) = v++"​++;​\n"​ show_p (PlusPlus v) = v++"​++;​\n"​