zero-order functions in haskell

Andrea Berger

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!

chepner

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.)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related