# Haskell dot operator with multiple parameters

I am doing exercise in fp-course
https://github.com/system-f/fp-course/blob/5e0848b4eacb3ddff65553ab5beb6447b73f61b3/src/Course/Applicative.hs#L357

``````replicateA n ka = sequence \$ replicate n ka
``````

I cannot use (.) to do `eta reduce` as follow. Maybe because `(.)` only accept one parameter.

``````replicateA = sequence . replicate   -- wrong
``````

Other example like flatMap

``````flatMap f xs = flatten \$ map f xs
flatMap = flatten . map             -- wrong
``````

How to use `eta reduce` when facing multiple parameters?

Solution

• If you really want to convert this function to point-free notation, you'll need to use the `(.)` infix operator twice. Let's start with what you have.

``````replicateA n ka = sequence \$ replicate n ka
``````

Let's write this with explicit parentheses

``````    replicateA n ka = sequence \$ (replicate n) ka
``````

Now this looks like function composition. Specifically, we're composing `sequence` and `(replicate n)`.

``````    replicateA n ka = sequence . replicate n \$ ka
``````

Now cancel off `ka`.

``````    replicateA n = sequence . replicate n
``````

Now operators are really just two-argument functions, so we can rewrite this as

``````    replicateA n = (.) sequence (replicate n)
``````

Again, this is function composition. We're just composing `(.) sequence` with `replicate`. So

``````    replicateA n = ((.) sequence) . replicate \$ n
``````

Cancel off the `n`.

``````    replicateA = ((.) sequence) . replicate
``````

Now rewrite `(.) sequence` to use an operator section.

``````    replicateA = (sequence .) . replicate
``````

Is this more readable than the original? No. But it's point-free now.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8139639,"math_prob":0.8656675,"size":1457,"snap":"2023-40-2023-50","text_gpt3_token_len":375,"char_repetition_ratio":0.21885754,"word_repetition_ratio":0.073275864,"special_character_ratio":0.25394645,"punctuation_ratio":0.14901961,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9676486,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-05T21:37:06Z\",\"WARC-Record-ID\":\"<urn:uuid:378cbc75-34af-4543-9d04-b6f13eaf09b8>\",\"Content-Length\":\"96043\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7100b415-1e8c-4790-8032-0416712eaf63>\",\"WARC-Concurrent-To\":\"<urn:uuid:a2efb799-673f-4130-8380-71b8182f35ff>\",\"WARC-IP-Address\":\"76.76.21.142\",\"WARC-Target-URI\":\"https://coderapp.vercel.app/answer/77199279\",\"WARC-Payload-Digest\":\"sha1:4QOYYH3UEWTXO6LBHLHIVWZATDXNFRJC\",\"WARC-Block-Digest\":\"sha1:O4IKU6E4SRRBMY452BQR4V6EEN2BE7MR\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100568.68_warc_CC-MAIN-20231205204654-20231205234654-00073.warc.gz\"}"}