2 May
2005
2 May
'05
3:52 p.m.
Andreas Fuertig writes:
fillArray ["a"] should be something like this: [[("a",True)],[("a",False)]]
A pretty generic solution using the "Bounded" and "Enum" type classes to calculate the list of all values for a given type would be: enumAll :: (Bounded a, Enum a) => [a] enumAll = [ minBound .. maxBound ] fillArray :: (Bounded b, Enum b) => [a] -> [(a,b)] fillArray xs = [ (x,y) | x <- xs, y <- enumAll ] In GHCi, you can use these functions like this: | *Main> enumAll :: [Bool] | [False,True] | | *Main> fillArray "abc" :: [(Char, Bool)] | [('a',False),('a',True),('b',False),('b',True),('c',False),('c',True)] Peter