0

The function (.) :: (b -> c) -> (a -> b) -> a -> c composes two functions which take only one argument each. I would sometimes find useful if the second function passed could take more than one argument:

(.) :: (b -> c) -> (a1 -> ... -> an -> b) -> a1 -> ... -> an -> c

If I use a function f as below with more than one argument as the second argument, this is what happens:

(g . f) val1 ... valn = g (f val1) val2 ... valn

Whereas I would like:

(g . f) val1 ... valn = g (f val1 ... valn)

Is there an alternative to . or another way to achieve this?

Guillaume Chérel
  • 1,478
  • 8
  • 17
  • 1
    you can always use `($)` in those cases! - I don't really see the necessity - can you give an example where you would need this? – epsilonhalbe Mar 06 '17 at 16:27
  • For a known number of arguments, you can compose partial applications of `(.)`. For example, `((g .) . f)` does what you want. It gets uglier as `f` takes more arguments, though. `h x y z = g (f x y z)` turns into `h = (((g .) . f) .) . f` – chepner Mar 06 '17 at 16:39
  • 1
    The "Variadic compose function?" suggested question covers your literal question (though you probably don't really want that -- cf. luqui's comment there). The other two discuss alternatives for when you know how many arguments you want to handle, along the lines of @chepner 's comment. – duplode Mar 06 '17 at 16:57

0 Answers0