Participating students are encouraged to post their questions related to programming assignments, exercises, and lectures
in this discussion forum, as well as answers and hints for fellow students. This serves two purposes:
- To stimulate interaction between students during the course. A lively discussion is beneficial for everyone.
- To minimize the startup time for the assignments (for instance, about the software we use, GHC flags that are required for compilation, etc.).
Needless to say, it is strictly prohibited
to include (partial) answers to assignments.
Can we use the UUAG system for the programming assignment?
Sure! You may use all available tools and libraries to get the job done.
Which (introductory) Haskell textbook do you recommend me?
Have a look at Jeroen Fokker's FP lecture notes
probably also available in printed form at the student desk). Another good textbook (in English) is written
by Simon Thompson
and can be ordered online.
- Some of you showed interest in (tutorials on) Category Theory. I would recommend to read Basic Category Theory for Computer Scientists by Benjamin C. Pierce (in the department's library, or just contact me). The material is definitely not suited for the faint-hearted. Remi has collected many other pointers to tutorials: you can also contact him.
- 09 Feb 2007
Comments by students:
If you found the
(\ ~(x:xs) -> x:x:xs) undefined
example confusing (like I did), it's probably because of a poor understanding of the type of undefined.
This example should make it clear.
\(x:xs) -> (head x,x,xs,[xs]) :: [[a]] -> (a,[a],[[a]],[[[a]]])
undefined :: a
(\~(x : xs) -> (head x,x,xs,[xs])) undefined :: (a,[a],[[a]],[[[a]]])
As Bastiaan said, undefined has the most general type. Even if you need an argument of type
, undefined will satisfy that type. The practical use of this "most general type" is for polymorphism.
E.g. the function
can be used on a variable of any type, because the type of its argument (and result) is the most general type.
are always a bit contrived. The main point I wanted to illustrate is whether some expression
is evaluated (because of pattern matching) or not. Let me show you a different example:
primes = sieve [2..]
where sieve (n:rest) = n : sieve (filter (\x -> x `mod` n > 0) rest)
bigprimes = drop 1000 primes
test1 (x:xs) = True
test2 ~(x:xs) = True
is an infinite list of prime numbers, and because the first 1000 numbers are skipped, it will take some time to
compute the head of this list (at least on my machine). Try the expression
and notice the delay (or type
to inspect the stats). On the other hand, the expression
does not evaluate
(But be careful: because
bigprimes is not a function, the part that is evaluated is shared/remembered by the interpreter.)
I hope this helps.
- 14 Feb 2007
If you use wxWidgets 2.6.3 and wxHaskell 0.10.0 on Mac OS X, you'll have to give the gameBoard (src/Ants.hs:68) a bgcolor attribute (e.g. white) to prevent the animation becoming unreadable.
- 17 Feb 2007
Does Haskell have indentation from hell? Example:
true = do something
If I change the name of the function to "false", it's suddenly 5 characters and the do statements don't line up, and ghc throws the beloved "parse error". How do you cope with this?
I've searched high and low and only come up with a barely passable indentation mode for vim
, which doesn't address the above scenario.
Something I've been doing (and indeed I've seen it suggested as good practice) is:
true = do
Now the sequence of statements can be indented with any number of tabs/spaces and will work whatever happens to the first line. It also frees you from the clutches of spaces. Purists would probably balk at this, though.
- 22 Feb 2007
Your solution (to write the first monadic statement under
the do keyword) does the trick. Did you know that you may write
the expressions something, totally, and awesome with less indentation than the do keyword (e.g., only 3 spaces)?
I have seen two other layout styles for do notation that do not have the problem you mentioned above:
- Also move do keyword to the next line (this is what I normally do: no pun intented here)
- Don't rely on the layout rule when programming in a do, but insert braces and semicolons.
- 23 Feb 2007
I experienced some difficulties getting wxhaskell to work on my Ubuntu (6.06 a.k.a. Dapper Drake) machine. I thought I'd share my solution to save other people with similar problems some time. The symptoms are:
- Inability to get the precompiled binary packages to work with ghc 6.4.1.
- Large volumes of compile errors when building wxhaskell.
- Complaints about undefined references when linking your wxhaskell program.
These installation instructions are based upon the instructions found at http://wiki.loria.fr/wiki/GenI/Getting_GenI/Instructions_for_Ubuntu_Linux#wxhaskell
, combined with some improvising and googling.
- Make sure you have the following packages installed:
- Build wxhaskell with the following commands:
darcs get http://darcs.haskell.org/wxhaskell
sudo make install
sudo make wx-install
- 25 Feb 2007
Apply the following fixes if you want to compile the ant simulator with ghc 6.6:
- The function
bounds no longer exists: use
getBounds instead, which has a slightly different type as it returns the bounds of an array in a monad (IO in our case). You have to modify three functions in
Caching.hs and the function
- The default background color of widgets changed from white into black. This means that you have to set the property
bgcolor to white for all panels in
Ants.hs, and for the
scrolledWindow in the function
gui in particular.
- 27 Feb 2007
Re: Space leaks lecture. Does ghc generate those fancy space charts or only the .prof files?
Compile your program with profiling enabled (
). Run your executable and provide a flag
to the runtime system (
): this will produce a
file. Next, you should use the
is shipped with
if I remember correctly) to generate a
file from the
file. Open de postscript
file and enjoy! Also see the ghc users guide
- 05 Mar 2007
A question :
It is maybe silly but it really bothers me. What does the phrase "first class" mean? I see it every where, like first class value, first class expression, first class library and etc.
(Bastiaan) Maybe reading http://en.wikipedia.org/wiki/First-class_function
- 09 Mar 2007
Incidentally, what does the Haskell community think of Common Lisp? Old? Flexible? Sloppy? Evil?
- 22 Mar 2007
When importing Quick Check in GHC I get these errors:
[2 of 3] Compiling QuickCheck ( QuickCheck.hs, interpreted )
QuickCheck.hs:147:52: Not in scope: `chr'
QuickCheck.hs:148:27: Not in scope: `ord'
QuickCheck.hs:155:41: Not in scope: `fromInt'
QuickCheck.hs:155:51: Not in scope: `fromInt'
The first is solved by importing chr and ord from module Char. But fromInt does not exist, according to hoogle.
- 26 Mar 2007
fromIntegral :: (Num b, Integral a) => a -> b
to convert an integer value (either
a different numeric type. I don't understand why you are compiling the Quick Check module: it is part of the
hierarchical libraries and it can thus be imported directly from your own module:
- 27 Mar 2007
Ah, what a stupid mistake. I did
which obviously did not work. Then I went to the QuickCheck website and it said that I needed to download QuickCheck.hs. But the QuickCheck.hs file found there is obviously a bit dated.
- 26 Mar 2007
Using this solution file http://urchin.earth.li/icfpcontest/2004/sub/solution-1.ant
and the sample6.world file, Joost saw that at step 2058 on the black ant hill, a red ant takes some food without actually being in the cell where the food is.
Is something wrong with the simulator?
- 29 Mar 2007
Hello Jeiel. I tried to reproduce the behaviour you described above, but I couldn't. How did you conclude that some ant
takes food that is not there? I hoped that your conclusion was not based on visual input since the food particles are
represented as circles and the radius of such a circle depends on the total number of particles in that cell.
For your information, the simulator has been tested quite
thoroughly (there was a lot of debug information made available during the actual contest to check whether a simulator
did conform to the specification: the AFP simulator implementation passed this test), but of course it is always possible
that somewhere a bug was introduced. Show it to me, or better, try to fix it yourself. Actually, this shouldn't be
too hard (and will be highly appreciated).
- 30 Mar 2007
I tried to reproduce it, but it did not work. Although Joost and I are certain of what we saw yesterday. We did determine it visually, but zoomed in as much as we could to be certain..
I looked again very closely and it does seem that when there is exactly one food dropped on a cell, the cell does not show it (step 1185 at the black ant hill). Only when the second food is dropped can you see a green circle. So that seems the most likely explanation for what we saw: there was exactly one food and the red ant picked it up. We will try to reproduce it later (it's not good to give a faulty reference
), but this makes the point moot.
- 30 Mar 2007
Eelco, Niels, and Reinier have modified the ant visualizer to show all markers. They agreed to share this
with all other teams.
- 10 Apr 2007