2 Test program for reading a binary file containing a sequence of
3 vectors of possibly different dimension. The format of the file is
6 -------------------------------- ---------------------
8 sizeof(int) bytes dimension of vector 1
9 sizeof(float) x dimension1 bytes vector 1
10 sizeof(int) bytes dimension of vector 2
11 sizeof(float) x dimension2 bytes vector 2
12 sizeof(int) bytes dimension of vector 3
13 sizeof(float) x dimension3 bytes vector 3
17 This program will print the dimension, then the vector, then a blank
18 line, then the dimension of the next vector, the next vector, then a
21 ----------------------------------------------------------------------
29 > main = getArgs >>= \ args ->
32 > [file] -> readFile file >>= \ bs ->
36 > putStrLn (display vs)
38 > _ -> error " need a binary file name"
42 > type Vector = [Float]
45 > readVectors :: Bytes -> [Vector]
47 > case readVector bs of
48 > Nothing -> [] -- assume there are no more vectors to read
49 > Just (v, bs') -> v : readVectors bs'
52 > readVector :: MST Bytes Vector
54 > readBytes `bindMST` \dimension ->
55 > listReadBytes dimension `bindMST` \v ->
60 > display :: [Vector] -> String
61 > display (v:vs) = displayVector v ++ display vs
64 > displayVector :: Vector -> String
65 > displayVector v = shows (length v) "\n" ++