[Haskell-cafe] How to parsing files
Sebastian Sylvan
sebastian.sylvan at gmail.com
Fri Jul 22 10:24:29 EDT 2005
On 7/20/05, yin <yin at atom.sk> wrote:
> Hi,
>
> I need to parse a file in this format:
> float float float
> float float float
> Each row has 3-columns of floating procision number divided by white
> space. The number of lines is undefined. I use (lines (readFile "..."))
> to read the file.
>
Off the top of my head:
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
Of course this won't exactly fail gracefully if the file is corrupt or
anything like that...
/S
--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862
More information about the Haskell-Cafe
mailing list