Seite **1** von **1**

### Sixth assignment now available

Verfasst: **25. Mai 2012 10:16**

von **sewe**

The sixth assignment (6 Tasks, 10 points overall) is now available:

https://cage.st.informatik.tu-darmstadt ... 012-05-25/. Please note: This assignment consists of two parts/files. Additionally, there is an example of a simple interpreter in monadic style which should be helpful when solving task 6:

https://cage.st.informatik.tu-darmstadt ... adic-ae.hs.

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.

### Re: Sixth assignment now available

Verfasst: **26. Mai 2012 14:53**

von **olg**

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?

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?

### Re: Sixth assignment now available

Verfasst: **26. Mai 2012 18:44**

von **Osterlaus**

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...???

### Re: Sixth assignment now available

Verfasst: **27. Mai 2012 01:11**

von **DanielSchoepe**

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.

### Re: Sixth assignment now available

Verfasst: **27. Mai 2012 12:02**

von **olg**

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.

### Re: Sixth assignment now available

Verfasst: **28. Mai 2012 10:19**

von **Osterlaus**

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...

### Re: Sixth assignment now available

Verfasst: **28. Mai 2012 17:12**

von **Osterlaus**

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

### Re: Sixth assignment now available

Verfasst: **28. Mai 2012 18:15**

von **sewe**

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* )

### Re: Sixth assignment now available

Verfasst: **28. Mai 2012 18:28**

von **sewe**

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.

### Re: Sixth assignment now available

Verfasst: **1. Jun 2012 13:45**

von **sewe**

### Re: Sixth assignment now available

Verfasst: **7. Jun 2012 21:05**

von **sewe**

(Finally), I marked the sixth assignment.

The

*points.txt*s are at the usual place in the SVN repository.