문제

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