I've started learning about Haskell and I'm trying to specify the Haskell type signature of an arbitrary zero-order function with Int type. As far as I understand, with first-order functions it would be something like k :: Int -> Int. Would that mean that the type signature of a zero-order function would be just k :: Int, or is it wrong to assume that? Thank you in advance!
There are no "zero order" functions in Haskell. Every function in Haskell has an arity of 1: each function takes one argument, and it returns one value. The return value itself could be another function. (A higher-order function is one whose argument and/or return type is itself a function type.)
k :: Int is not a function; it's just an Int.
The closest thing to a function with arity 0 in Haskell is a function of type () -> a for some type a. Because there is only one value of type (), there is only one way to call the function: with ().
k :: () -> Int
k () = 3
(You might notice that there is exactly one function of type () -> a for each value of type a; that's a matter of some theoretical importance, but isn't really relevant to the question here.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With