hashmap withdrawal and poor haskell style

D. Tweed tweed@compsci.bristol.ac.uk
Wed, 3 Apr 2002 13:27:24 +0100 (BST)


On Wed, 3 Apr 2002, Michal Wallace wrote:

> module Main where
>     alphabet = "abcdefghijklmnopqrstuvwxyz"
>     count ch str = length [c | c <- str , c == ch]
>     hist str = [count letter str | letter <- alphabet]
>     oneline ch str = [ch] ++ " " ++ stars (count ch str)
>     stars x = if x == 0
>               then ""
>               else "*" ++ stars ( x - 1 )
>     report str ch = do putStrLn ( oneline ch str )
>     loop f (h:t) = if t == []
>                    then f h
>                    else do f h
>                            loop f t
>     main = do content <- getContents
>               let rpt letter = report content letter
>               loop rpt alphabet
> """
> 
> Other than ignoring upper case letters, and being really
> really slow, it seems to work fine in hugs....

I'm a bit confused how this can have worked... in Haskell `let' is used in
the context of a `let ..<1>.. in ..<2>..' where the code ellided in <1>
binds some names to values which are then used in the expression <2> (as
in `let x=sqrt 2 in exp x') and so the contents of main isn't (unless I'm
missing something) syntactically Haskell.  

Overall the code looks like a reasonable transliteration into Haskell; as
you get more competent with Haskell you'll find various higher level
functions that replace some of your stuff, e.g., stars can be written as
stars x = take x (repeat '*').

Regarding Assoc, try just `import Assoc' without trying to cut down on
which entities are imported; if it works then you've missed some needed 
elements from your import specification (the bit in ()'s after the module
name); if it doesn't then it probably can't find Assoc at all.

HTH

___cheers,_dave_________________________________________________________
www.cs.bris.ac.uk/~tweed/|`...heat generated by its microprocessors will
email:tweed@cs.bris.ac.uk|slope upward exponentially, reaching the power
work tel:(0117) 954-5250 |density of a nuclear reactor before 2010'-Intel