
Take care here though, since Char might be unicode, you may be allocating a BIG array.
Whooa, that would be bad. In the unicode case, a FiniteMap would do great
since it is extended on the fly with new entries.
-- Daan.
----- Original Message -----
From: "Martin Norbäck"
import Array
type Histogram = Array Char Int
histogram :: String -> Histogram histogram input = accumArray (+) 0 (minBound,maxBound) [(c,1) | c <- input]
(The "minBound" and "maxBound" functions are overloaded from the "Bounded" class and give the minimal and maximal character).
Take care here though, since Char might be unicode, you may be allocating a BIG array. ghci: Ix.rangeSize (minBound :: Char, maxBound) 1114112 hugs: Ix.rangeSize (minBound :: Char, maxBound) 256 (1114112 is 17*2^16) Regards, Martin -- Martin Norbäck d95mback@dtek.chalmers.se Kapplandsgatan 40 +46 (0)708 26 33 60 S-414 78 GÖTEBORG http://www.dtek.chalmers.se/~d95mback/ SWEDEN OpenPGP ID: 3FA8580B