[Haskell-cafe] Seeking a small bug-fix for previously-posted code

Andy Elvey andy.elvey at paradise.net.nz
Sun Aug 14 21:36:33 EDT 2005

Hi all -

  I'm trying to run some code posted recently on this list ( the exact 
URI is as follows -
 (  The reason I'm doing this is because this code is quite close to 
what I'm trying to do. )

 Anyway,  I saved the code in a file called andy1.hs  .  The exact code 
is as follows -

module Main where
readVecs :: String -> IO [Vector3 GLfloat]
readVecs f =
    do str <- readFile f
         let mkVec [x,y,z] = Vector3 x y z
         return $ map (mkVec . read . words)  $ lines str

( I can see what the code seems to be doing : it's reading the file 
line-by-line, splitting it into "words", and filling the vectors with 
them.  Not too bad a guess for a "Haskellista" of a few minutes standing 
..... ;-)

I created a small file with whitespace-separated floats so that I could 
run the above code.
This data file looks like this -
23.596 38.201 79.903
32.647 65.559 15.438
21.648 34.978 90.089
55.587 76.763 96.634

When I run the above code (in GHCi , version 6.4) I get the message -
Prelude> :load andy1
Compiling Main             ( andy1.hs, interpreted )

andy1.hs:4:7: The last statement in a 'do' construct must be an expression
Failed, modules loaded: none.

So - I'm just wondering if anyone can see how the above code should be 
fixed in order to run.
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? 

Very many thanks in advance ...
 - Andy

More information about the Haskell-Cafe mailing list