My task consists in imitating features of an imperative programming language in Haskell. Now I'm struggling with assigning a value to a string. The point is that I have to do it with the types Env and Sigma. Env assigns a String (variable name) to a Location Loc. Sigma assigns the Location to a specific value. Here's the code:
type Loc = Int --Loc for Location
type Env = String -> Loc
type Sigma = Loc -> Int
assign :: String -> Int -> Env -> Sigma -> Sigma
assign name value env sig = \input -> ??
Now I don't know how to do it in the function assign of my program. The function should store the String name and the Location loc in the function env and also store the same location loc and the Value val in the function sig which must be returned by the whole function 'assign'.
Testing it with e.g. env = \"test"->42, sig= \42->6 (sig and env just provisionally for test case),assign "x" 45 env sig and then sig (env "x") should return 45. I don't know how you manage it to do without assigning the Locations to env and sig. Can you help me and tell me what I should do?
sig?sig (env "x")should return 45”?assigntype signature or theenvfunction in your test case is wrong. If the type signature is correct, your test case might look likelet { env x = case x of { "test" -> 42; "x" -> 43 }; sig = \42 -> 6 } in let { sig2 = assign "x" 45 env sig } in sig2 (env "x")