Seite 1 von 1

Fifth assignment now available

Verfasst: 11. Mai 2012 10:00
von sewe
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.

Re: Fifth assignment now available

Verfasst: 14. Mai 2012 11:09
von FeG
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

Re: Fifth assignment now available

Verfasst: 14. Mai 2012 22:58
von Geist
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...).

Re: Fifth assignment now available

Verfasst: 14. Mai 2012 23:12
von DanielSchoepe
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.

Re: Fifth assignment now available

Verfasst: 15. Mai 2012 09:42
von sewe
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.

Re: Fifth assignment now available

Verfasst: 15. Mai 2012 09:47
von sewe
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.

Re: Fifth assignment now available

Verfasst: 16. Mai 2012 15:16
von Osterlaus
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?

Re: Fifth assignment now available

Verfasst: 16. Mai 2012 17:35
von DanielSchoepe
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).

Re: Fifth assignment now available

Verfasst: 16. Mai 2012 18:24
von FeG
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.

Re: Fifth assignment now available

Verfasst: 16. Mai 2012 22:22
von sewe
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.

Re: Fifth assignment now available

Verfasst: 16. Mai 2012 23:24
von AlexanderF
hello,

I have also headache because of task 1 :-/.

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.

had anyone the same problem?

regards,
Alexander

Re: Fifth assignment now available

Verfasst: 16. Mai 2012 23:44
von DanielSchoepe
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. :)

Re: Fifth assignment now available

Verfasst: 17. Mai 2012 00:15
von AlexanderF
hello Daniel,
thanks for your effor,


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)

Re: Fifth assignment now available

Verfasst: 17. Mai 2012 00:26
von DanielSchoepe
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.

Re: Fifth assignment now available

Verfasst: 17. Mai 2012 00:48
von AlexanderF
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 :-)