What the following function definition / declaration means:
maxCollatz :: (Integer, Integer)
I am confused, because I am not sure what arguments takes and therefore what produces. Because normally there is ->
in the function definition. E. g. Int -> Int
.
P.S. Again sorry for this type of questions.
maxCollatz
is a pair of integers (Integer, Integer)
. It's not a function, it takes no arguments, and isn't called to produce anything; it just is a pair of integers.
The syntax for declaring the types of and then implementing top level declarations in Haskell is syntax for defining values. Functions are values, so they're included in that, but so is everything else.
The line of code is a valid function signature because it is important to understand that a function does not have to take any arguments.
The number of arguments a function takes is referred to as its arity.
In logic, mathematics, and computer science, the arity of a function or operation is the number of arguments or operands the function or operation accepts.
In this case, the function takes 0 arguments and is arity 0. A function with arity 0 is often referred to as a constant or nullary function.
In Python a similar function would look like this
def pair():
return (1,1)
If you are familiar with Python it is clear that this function takes no arguments and returns a pair of numbers. This is exactly what the function signature you provided describes.
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