Is it possible to write a function arity :: a -> Integer
to determine the arity of arbitrary functions, such that
> arity map
2
> arity fol
Yes, it can be done very, very easily:
arity :: (a -> b) -> Int
arity = const 1
Rationale: If it is a function, you can apply it to exactly 1 argument. Note that haskell syntax makes it impossible to apply to 0, 2 or more arguments as f a b
is really (f a) b
, i.e. not f applied to a and b
, but (f applied to a) applied to b
.
The result may, of course, be another function that can be applied again, and so forth.
Sounds stupid, but is nothing but the truth.