Haskell: Function to determine the arity of functions?

后端 未结 6 619
一个人的身影
一个人的身影 2021-02-05 07:00

Is it possible to write a function arity :: a -> Integer to determine the arity of arbitrary functions, such that

> arity map
2
> arity fol         


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-05 07:15

    It's not possible with standard Haskell. It may be possible using the IncoherentInstances or similar extension.

    But why do you want to do this? You can't ask a function how many arguments it expects and then use this knowledge to give it precisely that number of arguments. (Unless you're using Template Haskell, in which case, yes, I expect it is possible at compile time. Are you using Template Haskell?)

    What's your actual problem that you're trying to solve?

提交回复
热议问题