[Haskell-cafe] Seeking a small bug-fix for previously-posted code
Stefan Holdermans
stefan at cs.uu.nl
Sun Aug 14 06:05:00 EDT 2005
Andy,
Just a quick hack:
module Main where
import List -- ADDED
import Graphics.UI.GLUT -- ADDED
readVecs :: String -> IO [Vector3 GLfloat]
readVecs f =
do str <- readFile f
-- FIXED LAYOUT:
let mkVec [x,y,z] = Vector3 x y z
let format line = "[" ++ concat (intersperse "," (words line))
++ "]"
-- ADDED
return $ map (mkVec . read . format) $ lines str -- CORRECTED
So, the error message you got was layout-related, i.e., you needed to
move the last two lines of you programs two positions to the left.
Furthermore, you had to import the HOpenGL modules. Even then, your
code did not type check, so I replaced the application of words in the
last line by an application to a user-defined function format, that not
even makes it type check but also makes it actually reformat the input
so it can be consumed by read. I used intersperse to do this, so I also
needed to import the List module.
But, seriously, do you really think this is the way to learn Haskell?
> And just one last question - If the file looked like this (with column
> headings )
>
> Name Ethnicity Age
> Mary_Smith NZ_European 27
> Joe_Brown NZ_European 34
> John_Watson Canadian 45
> Mike_Tangaroa NZ_Maori 38
>
> - what change would the above code need to run?
I hope you don't mind I leave this to you as an exercise.
HTH,
Stefan
More information about the Haskell-Cafe
mailing list