> 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" <[EMAIL PROTECTED]> To: "Daan Leijen" <[EMAIL PROTECTED]> Cc: "Michal Wallace" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> 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 [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 _______________________________________________ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
