3 Date Started : 10th September 1992
4 Last Modified: 10th November 1992
6 This module allows the reading of lists of values from a string
7 of the one type seperated by white space.
9 Thanks to Paul Hudak for suggestions concerning getVals.
11 > module ReadLists (readWhiteList, readNumBools) where
14 readWhiteList reads a white-spaced list from a given string
16 > readWhiteList :: (Read a) => String -> [a]
17 > readWhiteList = getVals reads
20 readNumBools reads a list of white-spaced boolean values from a given
21 string. Booleans in a string are represented as 1's and 0's.
23 > readNumBools :: String -> [Bool]
24 > readNumBools = getVals readBool
26 > readBool :: ReadS Bool
28 > readBool (x:xs) = [(x == '1', xs)]
31 getVals (base function) takes a string, s, and a reading function, readVal,
32 and repeatedly applies readVal to s while removing whitespace
34 > getVals :: ReadS a -> String -> [a]
35 > getVals readVal s = case readVal (stripWhite s) of
37 > (x,s'):_ -> x : getVals readVal s'
40 stripWhite removes white space from the front of a string
42 > stripWhite :: String -> String
43 > stripWhite = dropWhile (`elem` " \t\n")