Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top