This is an excerpt from homework. “Prog
This datatype should have only one constructor and be used for representing programs of
the form:
read vin1 ; read vin2 ; < some statements > write vout2 ;
This constructor, which can also be named Prog, takes a string for the names of the two
input and one output variable.”
Define expProg to be of type Prog and to be the abstract syntax representation of the
program on the left above.
This should be done as follows:
expProg = Prog "x" "y" <some statements> "z"
I am new to Haskell and am confused by this.
I made a constructor like this. However this doesnt seem right.
data Prog = Prog String String String
deriving (Show,Eq)
Could anyone explain whats going on here? I do not understand how to make this constructor.
Here is the data type i made for statements:
data Stmt = Assing String Expr
| WhileLoop Expr Stmt
| Ifthen Expr Stmt
| IfthenElse Expr Stmt Stmt
| Composition [Stmt]
You said you needed to include “some statements” in the constructor as well. Currently, you only have room for the two input variables and the output variable. Simply add another field for the statements, for example like this:
Now you can use it like so:
(Note that it’s actually spelled
Assign, notAssing)