Search code examples
haskellpointfree

Point-free style and using $


How does one combine using $ and point-free style?

A clear example is the following utility function:

times :: Int -> [a] -> [a]
times n xs = concat $ replicate n xs  

Just writing concat $ replicate produces an error, similarly you can't write concat . replicate either because concat expects a value and not a function.

So how would you turn the above function into point-free style?


Solution

  • You can use this combinator: (The colon hints that two arguments follow)

    (.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
    (.:) = (.) . (.)
    

    It allows you to get rid of the n:

    time = concat .: replicate