Final Project - SImPL (Project 01)

112 views
Skip to first unread message

Ines Santos

unread,
Jan 5, 2018, 5:05:45 PM1/5/18
to Haskell-FER
Hello,

 I'm having some doubts regarding the project. I don't understand how State works or even what we are supposed to do in the extend function. 
Can anyone help me? 

Best regards and Happy New Year everybody!
Message has been deleted

Jasmin Zukić

unread,
Jan 6, 2018, 7:20:31 PM1/6/18
to Haskell-FER
I won't help too much but I'll say this.

Imagine,

st = extend empty "a" 5

st2 
= extend st "b" 3



st2 then becomes something like this:

extend extend empty "a" 5 "b" 3

I hope that can push you towards the solution a bit.

Another way you can think about it is this:
Since the extend function returns a State which is actually a function of String -> Int, you can use that to your advantage and backtrack through the chain of extends.

I hope I didn't spoil too much :)

Luka Hadžiegrić

unread,
Jan 7, 2018, 7:18:22 AM1/7/18
to Haskell-FER
State is just an alias for String -> Int which is a type signature for a function that takes in a String and returns an Int. In other words that is sort of a "dictionary" or a "key - value" data structure (even though it is a function) in which you can store new variables with extend function. Extend function should somehow "extend" our previous function and return new version of that function.

Since we can't really modify functions (or any value for that matter) the idea is to actually create a new function that checks if given String exists, and than returns that value. If that value doesn't exist than check if it maybe exists in the "old" state function.

I hope this helps. We can discuss this further during lectures next week if you want.
Reply all
Reply to author
Forward
0 new messages