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" <d95mback@dtek.chalmers.se> To: "Daan Leijen" <daan@cs.uu.nl> Cc: "Michal Wallace" <sabren@manifestation.com>; <haskell-cafe@haskell.org> Sent: Wednesday, April 03, 2002 5:54 PM Subject: Re: hashmap withdrawal and poor haskell style 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 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