ons 2002-04-03 klockan 15.51 skrev Daan Leijen: > > 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 [EMAIL PROTECTED]
Kapplandsgatan 40 +46 (0)708 26 33 60
S-414 78 G�TEBORG
http://www.dtek.chalmers.se/~d95mback/
SWEDEN OpenPGP ID: 3FA8580B
signature.asc
Description: PGP signature
