- Incrementer
f(x)=x+1
What this function do is to transform a number x into a number x+1 (ex: f(1)=2).
In Haskell, we write this function by the same way, where f is the name of the function and x is the argument and x+1 is the result.
The type of this f function would be
f :: Int -> Int
Note that the f function receives an int value (x) and returns another int (x+1)
(Click here to get more info about types)
So this function can be written like this:
f :: Int->Int
f x = x+1
The type of this function is
or in the extreme case
greater = >
So this function can be written like this:
f :: Int->Int
f x = x+1
- Greater
The type of this function is
greater :: Int -> Int -> Bool
And should be,initially, declared by this way
greater x y = if(x>y) then True else False
But the function >, declared at Prelude (where the basic functions, such as the sum, greater, etc, are declared), already returns a boolean value (True or False), so the declaration of the greater function can be done by this way:
greater x y = x>y
or in the extreme case
greater = >
Sem comentários:
Enviar um comentário