[Haskell-beginners] Help! I can't compile an example program
Tim Perry
tim.perry at lifetime.oregonstate.edu
Fri Jan 8 20:27:03 EST 2010
Hi all,
I found an example program that computes grades here:
http://donsbot.wordpress.com/?s=grades
I copied it to my computer and tried to compile it and if failed. Strangely enough, it works on the command line using 'runhaskell'. This makes me think I didn't set up the libraries correctly. So I downloaded and re-installed the Haskell Platform from:
http://hackage.haskell.org/platform/2009.2.0.2/HaskellPlatform-2009.2.0.2-setup.exe
The problem remains. I included the errors, the source and the results of runhaskell below. I hope someone can help me sort out what went wrong.
Thanks,
Tim
C:\Documents and Settings\perry\hs>ghc -O Grades.hs
Grades.o:fake:(.text+0x2f7): undefined reference to `containerszm0zi2zi0zi1_DataziMap_Tip_closure'
Grades.o:fake:(.text+0x930): undefined reference to `containerszm0zi2zi0zi1_DataziMap_lvl47_closure'
Grades.o:fake:(.text+0xa8b): undefined reference to `__stginit_containerszm0zi2zi0zi1_DataziMap_'
Grades.o:fake:(.text+0x219): undefined reference to `containerszm0zi2zi0zi1_DataziMap_insertWithKey_info'
Grades.o:fake:(.text+0x504): undefined reference to `containerszm0zi2zi0zi1_DataziMap_lookup_info'
Grades.o:fake:(.text+0x90e): undefined reference to `containerszm0zi2zi0zi1_DataziMap_polyzugo1_info'
Grades.o:fake:(.text+0x93f): undefined reference to `containerszm0zi2zi0zi1_DataziMap_foldr_info'
Grades.o:fake:(.data+0x50): undefined reference to `containerszm0zi2zi0zi1_DataziMap_insertWithKey_closure'
collect2: ld returned 1 exit status
C:\Documents and Settings\perry\hs>cat Grades.hs
import Data.Char
import Data.Maybe
import Data.List
import Data.Map hiding (map)
import Text.Printf
main = do
src <- readFile "grades.txt"
let pairs = map (split.words) (lines src)
grades = foldr insert empty pairs
mapM_ (draw grades) (sort (keys grades))
where
insert (s, g) = insertWith (++) s [g]
split [name,mark] = (name, read mark)
draw g s = printf "%s\t%s\tAverage: %f\n" s (show marks) avg
where
marks = findWithDefault (error "No such student") s g
avg = sum marks / fromIntegral (length marks) :: Double
C:\Documents and Settings\perry\hs>runhaskell Grades.hs
Alonzo [70.0,90.0,95.0] Average: 85.0
Bob [80.0] Average: 80.0
Eugenio [69.0] Average: 69.0
Henk [79.0] Average: 79.0
Oleg [77.0] Average: 77.0
Philip [73.0] Average: 73.0
Simon [94.0,99.0,93.0] Average: 95.33333333333333
C:\Documents and Settings\perry\hs>
More information about the Beginners
mailing list