AFP Course
Home
Education Page
Schedule
Literature
Assignment
Exercises
DSL Topics
Organization
Discussion Forum
Useful Links
Haskell Home
Haskell 98 Report
GHC Home
GHC Libraries
Profiling with GHC
Monad Tutorial
wxHaskell
HC&A Report
Haddock
Growing a Language
FFI in Haskell
Sources of Libs
wxHaskell docs
Center for ST
Home
Master Program
Center
Home
Courses
People
Projects
Page
Edit Page
Rename Page
Attach File
Printable
Wiki Source
More ...
Web
Recent Changes
Notify Service
News
Page Index
Search
More ...
Wiki
About TWiki
Text Formatting
Registration
Change Password
Reset Password
Users
Groups
Log In
or
Register
Discussion Forum
Afp0506
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. ------ MacOSX users: an easy way to install ghc(i) on your Mac is to use the [[http://www.darwinports.org/ports/?by=name&substr=ghc][darwinports]] project. I think there is a direct (DMG) installer on the http://www.haskell.org/ghc site as well, but darwinports allows you to install (and manage!) many other useful tools (such as subversion) as well. Check it out :) -- Main.SanderMak - 08 Feb 2006 *Urgent:* [[mailto:ebos@cs.uu.nl][Erica van den Bos]] is still looking for persons to team up with for the upcoming ant-challenge! In case anyone is interested, I have joined all the html pages of the tutorial "All About Monads" by Jeff Newbern (literature for week 2) together in one big PDF ([[%ATTACHURL%/Newbern-monads.pdf][Newbern-monads.pdf]]) for easy printing. (This involved manually printing each page to a file and then joining them all up with ghostscript... does anyone know of an easier way of converting multiple linked html files to a single PS/PDF file?) -- Main.KasperBrink - 09 Feb 2006 After a little test I got the following result: <verbatim> partition :: (a -> Bool) -> [a ] -> ([a], [a]) partition p xs = foldr select ([], []) xs where select x (ts, fs) | p x = (x : ts, fs) | otherwise = (ts, x : fs) partition' :: (a -> Bool) -> [a ] -> ([a], [a]) partition' p xs = foldr select ([], []) xs where select x ~(ts, fs) | p x = (x : ts, fs) | otherwise = (ts, x : fs) partition'' :: (a -> Bool) -> [a ] -> ([a], [a]) partition'' p xs = foldr select ([], []) xs where select x parts | p x = (x : ts, fs) | otherwise = (ts, x : fs) where ts = fst parts; fs = snd parts List>take 10 $ fst $ partition even [1..] *** Exception: stack overflow List>take 10 $ fst $ partition' even [1..] [2,4,6,8,10,12,14,16,18,20] List>take 10 $ fst $ partition'' even [1..] [2,4,6,8,10,12,14,16,18,20] </verbatim> -- Main.MichielOvereem - 10 Feb 2006 A small note: the first implementation doesn't work because the pattern match on =(ts, fs)= is performed _before_ the result tuple is constructed (the two right-hand sides of the guarded expressions). The second and third definition, on the other hand, both work because the pattern match on the second argument of =select= is performed _after_ the result tuple is constructed. For =partition'=, the pattern match is delayed because of the irrifutable pattern =~(ts, fs)=. For =partition''=, the pattern match is delegated to =fst= and =snd=, which is delayed until =ts= and =fs= are really needed. -- Main.BastiaanHeeren - 15 Feb 2006 For the people that do not want to print each of the papers separately, [[http://abaris.zoo.cs.uu.nl:8080/wiki/pub/Afp/DiscussionForum/papers_3_10.pdf][this]] is a PDF file(211 pages) with all the literature for week 3 and later. -- Main.EricBouwers - 15 Feb 2006 _Compilation problem_: trying to compile [[http://www.nomaware.com/monads/examples/example14.hs][IO Monad Example]] from Newburn's tutorial (ghc on mac), but I get this error: <verbatim> powerr:~/dev/priv_repo/afp/exc1-monad sbmak$ ghc --version The Glorious Glasgow Haskell Compilation System, version 6.4.1 powerr:~/dev/priv_repo/afp/exc1-monad sbmak$ ghc Test.hs /usr/bin/ld: Undefined symbols: _ControlziMonadziError_zdfMonadErrorIOException_closure ___stginit_ControlziMonadziError_ _ZCMain_main_closure ___stginit_ZCMain collect2: ld returned 1 exit status </verbatim> Compiling it on a Linux machine in BBL yields: <verbatim> ~/temp> ghc --version The Glorious Glasgow Haskell Compilation System, version 6.4 ~/temp> ghc Test.hs Test.o(.text+0x56): In function `r22m_info': : undefined reference to `ControlziMonadziError_zdfMonadErrorIOException_closure' Test.o(.text+0x8b6): In function `Test_main_info': : undefined reference to `ControlziMonadziError_zdfMonadErrorIOException_closure' Test.o(.text+0x8e9): In function `__stginit_Test_': : undefined reference to `__stginit_ControlziMonadziError_' Test.o(.data+0x0): In function `r22m_srt': : undefined reference to `ControlziMonadziError_zdfMonadErrorIOException_closure' Test.o(.data+0x4c): In function `Test_main_srt': : undefined reference to `ControlziMonadziError_zdfMonadErrorIOException_closure' /usr/lib/ghc-6.4/libHSrts.a(Main.o)(.text+0xe): In function `main': : undefined reference to `__stginit_ZCMain' /usr/lib/ghc-6.4/libHSrts.a(Main.o)(.text+0x28): In function `main': : undefined reference to `ZCMain_main_closure' collect2: ld returned 1 exit status </verbatim> It seems unable to link the Control.Monad.Error stuff (and maybe more?), do I need to pass any arguments to the compiler to make this work? *Update*: so, this works (I know, RTFM...): <verbatim> powerr:~/dev/priv_repo/afp/exc1-monad sbmak$ ghc -c Test.hs </verbatim> and this as well: <verbatim> powerr:~/dev/priv_repo/afp/exc1-monad sbmak$ ghc --make Test Chasing modules from: Test Compiling Test ( Test.hs, Test.o ) </verbatim> Now, how do I run the compiled stuff... next challenge :-) Ok, so the -c flag means 'stop before linking', so that's why I don't get the errors then... Apparently --make doesn't link either. Anyone with a clue what is going on here? -- Main.SanderMak - 15 Feb 2006 *Bastiaan*: I got the same error message on my Mac. Here is the command-line you were looking for: <verbatim> ghc --make -o test Test.hs </verbatim> After that you can call =strip test= to remove symbols from the executable =test=. Unless you are using a makefile, _always_ use the =--make= flag when using GHC to compile your sources. This instructs the compiler to build all the needed object files (.o) in the correct order, and to use all these files during linking (including libraries you use!). For your particular example, only the =lang= package is needed. Hence, =ghc -package lang -o test Test.hs= would also work. The =-o= flag specifies the name of the executable. For our Windows users: use =-o test.exe= instead. If you do not specify the name of the executable, GHC will call it =a.out=, which is really a silly name. _One more thing_: if you specify a module name in the file you are trying to compile other than Main, compilation will fail. Note that it is not necessary to call the file Main.hs in this case as would be with other modules. -- Main.SanderMak - 17 Feb 2006 *Monadic higher-order functions:* Last lecture, Kasper had a nice observation: you can also define _monadic higher-order functions_ to recurse over your data structures. The slides presented the function =transform=. I have rewritten this example using =foldTreeM= and =mapTreeM=. See [[%ATTACHURL%/MonadicHOF.hs][MonadicHOF.hs]]. -- Main.BastiaanHeeren - 20 Feb 2006 I hav a lot of problems with installing wxHaskell om my Win2K machine. I already considered installing Linux but it still want to make it work on Win2K :) The main problem with installing wxHaskell is =wxhaskell-register.bat=. The first error I discovered was the fact that the =%installdir%= variable does not have the right value, it is 1 dir too deep. When =/bin= or =/lib= is appended to the variable, the script fails because the =%installdir%= variable has value =../wxhaskell-0.9.4/bin= already! So the solution must be to adjust this variable. However, this does not solve the problem completely. When I run the script, or enter the commands manually, I keep getting the following error message: <verbatim> ghc-pkg: cannot find libwxcore.a on library path </verbatim> Does anybody have a clue what this error message is about? *Update:* The problem is solved, spaces in the file names killed the script :) So, install GHC and wxHaskell to a path without spaces! -- Main.ThomasVanNoort - 20 Feb 2006 The .bat files take the install-dir as an argument. The following command worked for me: <verbatim> wxhaskell-register.bat C:\Progra~1\GHC\wxhaskell </verbatim> -- Main.EricBouwers - 21 Feb 2006 *Precompiled binary of wxHaskell for Windows/GHC 6.4.1*: Martijn Schrage has compiled wxHaskell for Windows with GHC 6.4.1. The binary can be found at [[http://www.cs.uu.nl/wiki/Proxima/ProximaDownload]]. The Windows binary that can be found at the wxHaskell homepage only works with GHC 6.4.0. If the (compiled) binary of wxHaskell is not consistent with the version of GHC you have installed on your computer, you will get an error message like: <verbatim> E:\ghc-6.4.1\imports\wxhaskell-0.9.4\samples\wxcore\Minimal.hs:3:0: Failed to load interface for `Graphics.UI.WXCore': Bad interface file: E:\ghc-6.4.1\imports\wxhaskell-0.9.4\lib\imports/Graphics/UI/WXCore.hi mismatched interface file versions: expected 6041, found 6040 Failed, modules loaded: none. </verbatim> -- Main.BastiaanHeeren - 23 Feb 2006 For the people who don't like !PS (like myself...), [[%ATTACHURL%/TemplateHaskell.pdf][here]] is a PDF of the paper on Template Haskell. -- Main.ThomasVanNoort - 01 Mar 2006 Does anyone has the TemplateHaskell code running in ghci or ghc (on the BBL lab machines)? I've tried a number of commands: <verbatim> ghci -package Syntax -fth Test.hs ghci -package THSyntax -fth Test.hs ghci -package TH.Syntax -fth Test.hs ghci -package Language.Haskell.TH.Syntax -fth Test.hs </verbatim> These all result in the same message: ghc.exe: unknown package name: ... <verbatim> ghci -fth Test.hs </verbatim> this results in: Can't find module `Language.Haskell.TH.Syntax' Help, what is the correct command? -- Main.MichielOvereem - 09 Mar 2006 On the windows lab machines an older version of ghc (6.2.1) is installed. You have to use the package <verbatim> Language.Haskell.THSyntax </verbatim> instead of <verbatim> Language.Haskell.TH.Syntax </verbatim> You could of course ssh to a linux machine, the right version of ghc (6.4.x) is installed there. -- Main.MichielOvereem - 10 Mar 2006 I think there are a couple mistakes in the description of TemplateHaskell (actually it is just one, I misread something): <verbatim> test3 = $(permute [0,2,1]) foldr 0 (+) [1..10] </verbatim> should be <verbatim> test3 = $(permute [1,0,2]) foldr 0 (+) [1..10] --foldr (+) 0 [1..10] = 55 </verbatim> Am I correct or am I missing something? -- Main.MichielOvereem - 13 Mar 2006 Ah, nothing like a good old-fashioned build error: <verbatim> HInteractive.hs:351:12: lexical error in string/character literal make[1]: *** [/import/enterprise/home/sbmak/afp/exc4/hmake-3.10/lib/ix86-Linux/HInteractive] Error 1 make[1]: Leaving directory `/import/enterprise/home/sbmak/afp/exc4/hmake-3.10/src/interpreter' make: *** [targets/ix86-Linux/hi-ghc] Error 2 </verbatim> This is occurs while making hmake on the student pc's... anyone have a clue what's going on? *Update:* Oh well, I replaced the (huge, multiline) strings which the error points to with some trivial (one-line) string, and all is well... no need for ASCII art :-) Strange error though, how could something like this have slipped through in a stable distribution? -- Main.SanderMak - 28 Mar 2006 Here are some notes on how to build and install =hmake= and =hat= as a normal (non-root) user (sorry, no Makefile...). ------------------------------------------------------------------------------- 1. First, set an environment variable pointing to where you want the files to be installed <verbatim> export PREFIX=~/path/to/installdir </verbatim> 2. Get =hmake=, untar it, and change into the toplevel dir. Doing this on a local filesystem (e.g. =/tmp=) should speed things up a bit. <verbatim> wget http://www.haskell.org/hmake/hmake-3.10.tar.gz tar xvzf hmake-3.10.tar.gz cd hmake-3.10 </verbatim> 3. replace =src/interpreter/HInteractive.hs= with this file: [[%ATTACHURL%/hmake_src_interpreter_HInteractive.hs][hmake_src_interpreter_HInteractive.hs]] %BR% _(this will remove all newlines inside the two strings at the end of the file, i.e. =banner==... and =help==...)_ 4. (Fedora Core 4 users: edit =script/confhc=; change line 81. This step is *not* necessary on the lab machines.) <verbatim> - grep -v '^#' ghcsym.out > $2; + grep '^[0-9]\+$' ghcsym.out > $2; </verbatim> 5. build "as normal" <verbatim> ./configure --prefix=$PREFIX make make install </verbatim> 6. Remember to add =$PREFIX/bin= to your =PATH= before proceeding! %BR% (you probably also want to do this in your =~/.bashrc=, with =$PREFIX= expanded) <verbatim> export PATH=$PREFIX/bin:$PATH </verbatim> ------------------------------------------------------------------------------- 7. Get =hat=, untar it, and change into the toplevel dir. <verbatim> wget ftp://ftp.cs.york.ac.uk/pub/haskell/hat/hat-2.04.tar.gz tar xvzf hat-2.04.tar.gz cd hat-2.04 </verbatim> 8. Replace =script/confhat= with this file: [[%ATTACHURL%/hat_script_confhat][hat_script_confhat]], and make sure that it is executable (=chmod +x script/confhat=).%BR% _(for the curious:) This fixes several problems: =libdir= is now set to =$PREFIX/lib= from the environment; the script now uses the new =ghc-pkg= syntax and includes the =--user= flag; and =Hat.PreludeBuiltin= is added to the exported module list._ 9. (Fedora Core 4 users: edit =script/confhc-hat=; change line 59. This step is *not* necessary on the lab machines.) <verbatim> - grep -e '^[0-9]*$' ghcsym.out > $2 + grep '^[0-9]\+$' ghcsym.out > $2 </verbatim> 10. build as normal. Note that the script you changed in step 8 depends on having =$PREFIX= in the environment! <verbatim> ./configure --prefix=$PREFIX make make install </verbatim> ------------------------------------------------------------------------------- Good luck! -- Main.KasperBrink - 29 Mar 2006 Well, I spent almost the whole evening (I know...) to get it to work on either my Mac or on a student-linux pc, but both seem to fail at actually compiling the sorting example (./Sorting/Mmain.hs). First I try this: <verbatim> ~/afp/exc4/files/Sorting>hmake -hat -v Mmain <..snip..> Hat/Mmain.hs:17:9: Could not find module `Hat.PreludeBuiltin': locations searched: Hat/PreludeBuiltin.hi Hat/PreludeBuiltin.hi-boot </verbatim> and then, using the include directive I get this: <verbatim> ~/afp/exc4/files/Sorting>hmake -hat -i/users/sbmak/hat/lib/imports/hat/ -v Mmain Hat/Mmain.hs:17:9: Interface file inconsistency: home-package module `Hat.PreludeBuiltin' is mentioned, but does not appear in the dependencies of the interface </verbatim> Error messages are similar on the mac. I'm starting to hate this thing... -- Main.SanderMak - 29 Mar 2006 Sander, I was able to reproduce your error on the student machines, and my own (Fedora Core 4) machine. It seems that although the =PreludeBuiltin= modules are being installed correctly, they are not registered properly in the Cabal package management system. By manually adding =Hat.PreludeBuiltin= to the exported modules list, I was able to get Mmain.hs, and several other examples, to compile without errors (plenty of warnings though!). You could repeat the steps 7-10 I listed above with the (updated) [[%ATTACHURL%/hat_script_confhat][hat_script_confhat]] script which I've fixed to add =PreludeBuiltin= in the appropriate place. Or, if you still have a hat build tree lying around, you could just update =script/confhat= and rerun =make install=. Or for a really quick (untested!!) workaround, try <verbatim> ghc-pkg describe hat > hat.conf cat hat.conf | sed -e 's/^exposed-modules:.*$/& Hat.PreludeBuiltin/' | ghc-pkg --user update - </verbatim> -- Main.KasperBrink - 29 Mar 2006 I had to add the following line to hat-20.4/lib/ix86-Linux/hatlib/ghc/hat-package.conf: <verbatim> library-dirs: /var/tmp/hmake/hat-2.04/lib/ix86-Linux/hatlib/ghc </verbatim> -- Main.MichielOvereem - 30 Mar 2006 Michiel: hmmm, interesting. You seem to be pointing it at the part of the _build_ tree that is copied to =$PREFIX/lib/imports/hat= after installation; but the "import-dirs" field already points to that... Are you sure that the =libHShat.a= file is being copied correctly when you make install? It should end up in the =$PREFIX/lib= directory, and then you probably won't have to touch the .conf file at all. Or maybe you've found yet another strange bug in the install scripts, it wouldn't be the first. Of course, if this works for you, then I'd just be happy and leave it alone... But it does make it hard to throw away your build tree after installation, or work on multiple machines. -- Main.KasperBrink - 30 Mar 2006 Ok, on a somewhat lighter note then :-) While reading up on arrows, I stumbled across this: * There is a preprocessor that reads as input a Haskell script augmented with arrow notation, and outputs a plain Haskell script. * The notation is also implemented directly in GHC, from version 6.2, where it is enabled by the -farrows option. Error reports for arrow notation are considerably clearer, and refer to the original source. The documentation accompanying GHC has more details. ('the notation' meaning the proc notation which Xiaoyu showed us earlier today, which I thought to be Yampa specific, but is for all arrows) Source: http://www.haskell.org/arrows/syntax.html -- Main.SanderMak - 31 Mar 2006 <h1>*ANNOUNCEMENT:*</h1> After several weeks of sleepless nights for the team consisting of Eric, John, Michiel and Thomas, the hard work finally paid off! We would like to thank Sander's team for pimpin' the simulator, Mark's team for using Monads, Elmar's team for going crazy, and of course our mothers :) Warm, fuzzy, season greetings from The Winners!