:
.
xs, , x [x, x] ; , . - :
k :: a -> [a]
k x = [x,x]
g :: (a -> b) -> [a] -> [b]
g f [] = []
g f (x:xs) = f x : g f xs
duplicate :: [a] -> [a]
duplicate = concat . (g k)
g = map concat . g = concatMap, , , :
duplicate :: [a] -> [a]
duplicate = concatMap (\x -> [x,x])
=> concatMap (replicate 2)
a b, , b a:
f :: Eq a => a -> a -> a -> a
f o r x = if x == o then r else x
replaceOn :: Eq a => a -> a -> [a] -> [a]
replaceOn o r [] = []
replaceOn o r (x:xs) = f o r x : h o r xs
h = map f, :
replaceOn :: a -> a -> [a] -> [a]
replaceOn o r = map (\x -> if x == o then r else x)
I am not an Haskell expert. However, this helps me break down Haskell's problems into sequences of "return values". It is like “steps” in an imperative language. The steps are composed using combinators, higher order functions, and ordering functions. You can think of a sequence, for example: do f to get x; on g with fx to get x ', etc.
source
share