Haskell (.) for function with multiple operands

瘦欲@ 提交于 2019-12-06 01:59:33

问题


The (.) operator has the signature:

(.) :: (b -> c) -> (a -> b) -> a -> c
(.) f g x = f $ g x

This looks a bit similar to the composition function in primitive recursive functions with one g.

I'm not interested in extending the number of g-functions, but (a number of) functions that apply the (.) function on a function g with multiple operands. In other words something like:

(..) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
(..) f g x y = f $ g x y

A search on Hoogle doesn't result in any function. Is there a package that can handle this with an arbitrary number of operands?


回答1:


To answer-ify my comments:

Multi-argument function composition operators are very easy to define, and luckily someone has done this for you already. The composition package has a nice set of operators for you to use to compose functions in this manner. I also find that instead of using haskell.org's hoogle engine, fpcomplete's version searches through more packages making it easier to find what I'm looking for.



来源:https://stackoverflow.com/questions/28532836/haskell-for-function-with-multiple-operands

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!