[Haskell-cafe] How to solve this problem?It's quite easy in PHP.
Gene A
yumagene at gmail.com
Thu Feb 15 17:30:16 EST 2007
On 2/15/07, Gene A <yumagene at gmail.com> wrote:
> Haskell solution:
> build the array of all lower case with corresponding numbers starting with 1
>
> Prelude> let lowerCaseTable = zip ['a'..'z'] [1..26]
>
> A couple of functions:
> Prelude> let box a = a:[]
> Prelude> let formatTableItems (a,b) = (box a) ++ " = " ++ (show b) ++ "\n"
>
> Then to output the results:
> putStrLn $ foldr (++) "\n"$ map formatTableItems lowerCaseTable
> a = 1
> b = 2
That last output function group could have been simpler.. I sometimes
forget concatMap.. as I did there it should have been:
Prelude> putStrLn $ concatMap formatTableItems lowerCaseTable
a = 1
b = 2
c = 3
etc....
even simpler than the first.. where I used map and then foldr
cheers,
gene
More information about the Haskell-Cafe
mailing list