質問

So a function to replicate the elements of a list a given number of times looks like this

rep :: Int -> [a] -> [a]
rep = concatMap . replicate

by definition (f . g) x = f(g(x)) but

(concatMap (replicate 4 "abc")) is not working same as (concatMap . replicate) 4 "abc". In fact it doesn't work at all. And concatMap's first parameter must be function. I'm getting confused by this. How is that point free version even working? Can anyone explain it please.

役に立ちましたか?

解決

You're right that (f . g) x = f (g x), but that doesn't mean that (concatMap . replicate) 4 "abc" = concatMap (replicate 4 "abc"). Rather, it means that (concatMap . replicate) 4 "abc" = concatMap (replicate 4) "abc", which is true.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top