>
> Exercise 1.14 A function for transforming strings into strings is of
> type String
> -> String. Write a function blowup that converts a string
> a1 a2 a3 · · ·
> to
> a1 a2 a2 a3 a3 a3 · · · .
> blowup "bang!" should yield "baannngggg!!!!!". (Hint: use ++ for
> string
> concatenation.)
我先抛块砖 :-)
ACA80110:tmp lee$ cat blowup.hs
module Blowup where
repeatn p = take n (repeat c)
where c = fst p
n = snd p
blowup ss = foldr (++) [] (map repeatn (zip ss [1..]))
ACA80110:tmp lee$ ghci blowup.hs
GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help
Loading package base ... linking ... done.
[1 of 1] Compiling Blowup ( blowup.hs, interpreted )
Ok, modules loaded: Blowup.
*Blowup> blowup "bang!"
"baannngggg!!!!!"
*Blowup>
lee