[Haskell-cafe] How to solve this problem?It's quite easy in PHP.
Gene A
yumagene at gmail.com
Thu Feb 15 17:17:11 EST 2007
On 2/13/07, keepbal <keepbal at gmail.com> wrote:
> For example,
(...
> $arr['a']='1';
> $arr['b']='2';
> $arr['c']='3';
...) result:
> a = 1
> b = 2
> c = 3
-------------
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
c = 3
d = 4
e = 5
f = 6
g = 7
h = 8
i = 9
j = 10
k = 11
l = 12
m = 13
n = 14
o = 15
p = 16
q = 17
r = 18
s = 19
t = 20
u = 21
v = 22
w = 23
x = 24
y = 25
z = 26
I think that is pretty simple...
Good cheer to all from the desert,
gene
More information about the Haskell-Cafe
mailing list