## Fifth assignment now available

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

### Fifth assignment now available

The fifth assignment (7 Tasks, 10 points overall) is now available: https://cage.st.informatik.tu-darmstadt ... 012-05-11/ Please note: This assignment consists of two parts/files.

This assignment is due on Thursday, 17 May 2012, 23:59. (Yes, I know it's a public holiday; we just want to keep our one-week rhythm.) Please commit your solution till then into your group's SVN directory under a subdirectory named 2012-05-11: https://cage.st.informatik.tu-darmstadt ... -pt[12].hs.

FeG
Endlosschleifenbastler
Beiträge: 182
Registriert: 6. Dez 2007 07:01

### Re: Fifth assignment now available

Hi,

are we allowed to use Haskell's standard function (e.g., from base Data.List) to implement the functions we're required to implement in the 2nd part?

Best,
Felix

Geist
Neuling
Beiträge: 7
Registriert: 15. Nov 2005 17:08
Wohnort: Dachboden

### Re: Fifth assignment now available

Hello

I have a bit of a problem with the behavior of the predefined combine:

Code: Alles auswählen

take 20 (combine [1..] [ div x 5 | x <- [1..]])
[0,0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4]
do we have to mimic this or only for the given test case?
mimicking the above test will be quiet annoying if we have to use distinct (because it is counterproductive here...).

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

### Re: Fifth assignment now available

FeG hat geschrieben: are we allowed to use Haskell's standard function (e.g., from base Data.List) to implement the functions we're required to implement in the 2nd part?
If I remember correctly, Andreas said that we could use anything we find in the base package that comes with GHC.

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

### Re: Fifth assignment now available

FeG hat geschrieben:are we allowed to use Haskell's standard function (e.g., from base Data.List) to implement the functions we're required to implement in the 2nd part?
DanielSchoepe hat geschrieben:If I remember correctly, Andreas said that we could use anything we find in the base package that comes with GHC.
Yes, in general you can use functions from Data.List.

However, this might make it difficult to argue about the behaviour of combine2 in Task 7, as the argument would then depend on the library functions' implementations. In this case, my recommendation is therefore to stick to functions you wrote yourself (copy-&-paste from the standard library is OK, too), so that all code necessary for the argument sits in plain sight.

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

### Re: Fifth assignment now available

Geist hat geschrieben:Hello

I have a bit of a problem with the behavior of the predefined combine:

Code: Alles auswählen

take 20 (combine [1..] [ div x 5 | x <- [1..]])
[0,0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4]
do we have to mimic this or only for the given test case?
mimicking the above test will be quiet annoying if we have to use distinct (because it is counterproductive here...).
As you rightly point out, this would indeed be annoying if you have to use distinct. That's why inputs like these were specifically excluded in the task:

"Use "merge" and "distinct" to implement the function "combine2", which must have the same functionality as the function "combine" given below, for the case when the argument lists are strictly increasing." Your second argument list ([0,0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3, ...]) violates this property.

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

### Re: Fifth assignment now available

Yeeeah, just for the records: The first task, about polymorphism, caused a lot of headache for me. After having asked a friend, it was not that difficult at all - because you gave a tiny hint about algebraic data types in class last friday, which I could not attend. Would it be possible to write down these hints also in the assignment files, just for these people who cannot be at the presentation?

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

### Re: Fifth assignment now available

Just for completness: another very helpful hint for that task was: "If you're writing code, you're doing it wrong." (in the sense of writing/changing things that aren't datatype definitions or type signatures).

FeG
Endlosschleifenbastler
Beiträge: 182
Registriert: 6. Dez 2007 07:01

### Re: Fifth assignment now available

Osterlaus hat geschrieben:Would it be possible to write down these hints also in the assignment files, just for these people who cannot be at the presentation?
I definitely second that! We too investend several hours to figure out the first task The hint did not reached us, as we can't attend the exercise class due to parallel lectures.

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

### Re: Fifth assignment now available

Sorry about that. I'll try to post any major hints (if they are not included in the task's description already) in the forum as well. Seems like there are quite a few people who have conflicting lectures on Friday (which is especially unfortunate this week, with their being a lecture rather than an exercise on Friday).

That being said, it's OK to ask for hints in the forum, too. Either myself or your fellow students can probably supply you with a hint - without giving away the solution.

AlexanderF
BASIC-Programmierer
Beiträge: 140
Registriert: 2. Mai 2010 17:55

### Re: Fifth assignment now available

hello,

Is it realy sufficient to change datatype definitions or type signatures ?

I did this, so that the 2 datatypes and the type are depending on a Number n.
hence I also had to change the signatur of interp,

but now I get an error message for interp for AppE argument,
that no instance for (Num n) arise?

so, what did I wrong,
I have no idea.

regards,
Alexander

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

### Re: Fifth assignment now available

AlexanderF hat geschrieben: I did this, so that the 2 datatypes and the type are depending on a Number n.
hence I also had to change the signatur of interp,

but now I get an error message for interp for AppE argument,
that no instance for (Num n) arise?
Depending on how old your GHC (This happens only* with GHCs older than 7.2.1) is, you may have run into a bad design decision that was made in Haskell 98 (the original language spec) that has since been removed from the language:

It was possible to add a constraint to a datatype declaration, e.g.

Code: Alles auswählen

data Num a => Foo a = MkFoo a

However, this constraint was ignored when defining functions using that datatype, so this would generate an error saying that GHC doesn't know anything about a being a Num:

Code: Alles auswählen

f :: Foo a -> Foo a - > Foo a
f (MkFoo x) (MkFoo y) = MkFoo (x + y)

This datatype constraint thing is pretty confusing as you have to remember all the constraints of a type when reading a function's type signature. Hence, it was removed in Haskell 2010 (the latest language standard). The
proper way to do this kind of thing is to add the constraints to the functions that actually make use of the type class methods instead (as you had to before anyway, but this point also shows why this is the correct
way to fix this issue).

Perhaps this was causing your problem.

* Unless you explicitly enable it, but then GHC will give you a stern warning not to do that.
Zuletzt geändert von DanielSchoepe am 17. Mai 2012 00:55, insgesamt 2-mal geändert.

AlexanderF
BASIC-Programmierer
Beiträge: 140
Registriert: 2. Mai 2010 17:55

### Re: Fifth assignment now available

hello Daniel,

Im not sure whether I understand right what you want to say,

anyway, I installed GCHi a few weeks ago,
so I think I have a newer version.
and I changed the function signatur,
for the first parameter for example,
I replaced FAE with (FAE n)

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

### Re: Fifth assignment now available

You can see what version of GHC you have by running "ghc --version" (even Debian testing only has 7.0.4, so this old-GHC-pitfall is not overly unlikely).

Your problem may be simpler though: Remember that the signature of, say, (==) is "Eq a => a -> a -> Bool" and not just "a -> a -> Bool". You have to make a similar addition here (remember that we don't want to allow arbitrary types, but only numeric types).

The point of my previous post was that you have to make that addition in the function's type signature, not when defining the datatype, which the language unfortunately allowed in the past.

AlexanderF
BASIC-Programmierer
Beiträge: 140
Registriert: 2. Mai 2010 17:55

### Re: Fifth assignment now available

DanielSchoepe hat geschrieben:Your problem may be simpler though: Remember that the signature of, say, (==) is "Eq a => a -> a -> Bool" and not just "a -> a -> Bool". You have to make a similar addition here (remember that we don't want to allow arbitrary types, but only numeric types).
thanks, this hint was what I needed