## Sixth assignment now available

sewe
Sonntagsinformatiker
Beiträge: 295
Registriert: 16. Jan 2009 14:53
Kontaktdaten:

### Sixth assignment now available

This assignment is due on Thursday, 31 May 2012, 23:59.

That being said, there has been a technical problem with the repository. If you are unlucky, you may need to check out the whole repo again: svn co https://cage.st.informatik.tu-darmstadt.de/2012/copl. Sorry about that.

olg
Sonntagsinformatiker
Beiträge: 297
Registriert: 1. Okt 2008 19:24

### Re: Sixth assignment now available

Is the return type of "runWithCounter" in the assignment-pt2 wrong, or am I missing something?

Test5 expects the return type of runWithCounter to be (a, Int), but the declaration suggests to return only a?

Code: Alles auswählen

runWithCounter :: State Int a -> a

If I'm changing the return type of runWithCounter to (a, Int), test5 succeeds.

Additionally, i'm having some difficulties finding a proper implementation for myseq. Can you give me a small hint? I'm currently trying to force the evaluation for each member of 'Value' by calculating on the resulting value, without actually returning the result of that operation. Is there an easier way?
"To Perl, or not to Perl, that is the kvetching." ~Larry Wall

Osterlaus
BSc Spammer
Beiträge: 1263
Registriert: 23. Aug 2007 12:46
Wohnort: DA

### Re: Sixth assignment now available

I'm stuck at another point: as far as I can see, the method incr only returns a state. How does it know about the counter it should increment...???

DanielSchoepe
Mausschubser
Beiträge: 49
Registriert: 28. Sep 2009 11:39

### Re: Sixth assignment now available

olg hat geschrieben:Test5 expects the return type of runWithCounter to be (a, Int), but the declaration suggests to return only a?
Is it possible that you accidentally changed the type of runWithCounter yourself? It has the result type (a, Int) here.
Osterlaus hat geschrieben:I'm stuck at another point: as far as I can see, the method incr only returns a state. How does it know about the counter it should increment...???
Take another look at the definition of the State data type. Think about how you can construct a value of that type.

olg
Sonntagsinformatiker
Beiträge: 297
Registriert: 1. Okt 2008 19:24

### Re: Sixth assignment now available

DanielSchoepe hat geschrieben:
olg hat geschrieben:Test5 expects the return type of runWithCounter to be (a, Int), but the declaration suggests to return only a?
Is it possible that you accidentally changed the type of runWithCounter yourself? It has the result type (a, Int) here.
It seems like I have. I've checked the exercises, and the result type is correct. Sorry for the confusion.
"To Perl, or not to Perl, that is the kvetching." ~Larry Wall

Osterlaus
BSc Spammer
Beiträge: 1263
Registriert: 23. Aug 2007 12:46
Wohnort: DA

### Re: Sixth assignment now available

DanielSchoepe hat geschrieben:
Osterlaus hat geschrieben:I'm stuck at another point: as far as I can see, the method incr only returns a state. How does it know about the counter it should increment...???
Take another look at the definition of the State data type. Think about how you can construct a value of that type.
Sorry, but that doesn't help me any further...

Osterlaus
BSc Spammer
Beiträge: 1263
Registriert: 23. Aug 2007 12:46
Wohnort: DA

### Re: Sixth assignment now available

One more question. How can we be sure to have the eager evaluation done properly? We could also throw the error if the lookup fails, without any transition to eager evaluation.

I'm a bit surprised by the current assignment. Besides the first two tasks, that were not that difficult, I run into dead ends at any task

sewe
Sonntagsinformatiker
Beiträge: 295
Registriert: 16. Jan 2009 14:53
Kontaktdaten:

### Re: Sixth assignment now available

olg hat geschrieben:Additionally, i'm having some difficulties finding a proper implementation for myseq. Can you give me a small hint? I'm currently trying to force the evaluation for each member of 'Value' by calculating on the resulting value, without actually returning the result of that operation. Is there an easier way?
Here's a hint: Your current implementation is a good first step, but already goes too far. Why do you need to calculate stuff with the Int wrapped inside a NumV? You only need to force Haskell to "materialize" said Int. How can you do that? (Hint works analogously for ClosureV, but "calculate stuff" makes more sense for a NumV )

sewe
Sonntagsinformatiker
Beiträge: 295
Registriert: 16. Jan 2009 14:53
Kontaktdaten:

### Re: Sixth assignment now available

Osterlaus hat geschrieben: One more question. How can we be sure to have the eager evaluation done properly? We could also throw the error if the lookup fails, without any transition to eager evaluation.
The point is that with lazy evaluation you may not even get to the point where the lookup is performed. Maybe if you could post some code for the interpreter here, I could construct a counterexample, i.e., a program where the error call won't be reached due to laziness.
Osterlaus hat geschrieben:I'm a bit surprised by the current assignment. Besides the first two tasks, that were not that difficult, I run into dead ends at any task
Can you turn this into a more specific question please?

Anyway, here are some more generic hints:
• For task 3, review the lecture's slides on strictness points again and first think where those points should be in the interpreter before writing any code.
• For task 5, mentally expand the type (State) to its definition; if you are new to monads looking under the hood, i.e., thinking in terms of s -> (a, s) is a good idea.
• For task 6, try to convert the interpreter into monadic style first (without using incr; just use the Identity monad like in monadic-ae.hs.) Only then add the calls to incr.
Hope this helps a bit.

sewe
Sonntagsinformatiker
Beiträge: 295
Registriert: 16. Jan 2009 14:53
Kontaktdaten:

### Re: Sixth assignment now available

The model solutions are now in the SVN repository: https://cage.st.informatik.tu-darmstadt ... 012-05-25/.

sewe
Sonntagsinformatiker
Beiträge: 295
Registriert: 16. Jan 2009 14:53
Kontaktdaten:

### Re: Sixth assignment now available

(Finally), I marked the sixth assignment.

The points.txts are at the usual place in the SVN repository.