FYI: Second day into Haskell
MRE (what the function does, does not matter):
foo :: Int -> Int -> Int
foo x y
| x == y = x + y
| x < y = x
| x > y = y
This is what I’ve gathered about the ->
operator(?) so far:
- It is right-associative
- It is used in function type declaration to denote the type of function parameters as well as its return type
Now take a look at the following function type declaration:
foo :: Int -> Int
This declares(what is the appropriate word?) a function called foo
that takes an Int
and returns an Int
.
However, the declaration: foo :: Int -> Int -> Int
declares(?) that foo
takes 2 Int
s and returns an Int
when it is the same as saying foo :: Int -> (Int -> Int)
which is a function that takes an Int
and returns a function that takes an Int
and returns an Int
.
How does this make sense? Should it not be something on the lines of Int,Int -> Int
?
PS: The book I’m using: Thinking Functionally with Haskell by Richard Bird.