Could someone explain why there is 27
different Bool->Bool
values, from which 11
can be definied in Haskell?
There are 27 functions from a three-value set to a three-value set.
We can also compare two numerical values to see which one is larger. Haskell provides a number of tests including: < (less than), > (greater than), <= (less than or equal to) and >= (greater than or equal to). These tests work comparably to == (equal to).
The boolean type Bool is an enumeration. The basic boolean functions are (&&) (and), (||) (or), and not. The name is defined as True to make guarded expressions more readable. Definition: data Bool = False | True deriving (Read, Show, Eq, Ord, Enum, Bounded)
There are three values of type Bool
: True
, False
and bottom (expressions for which the evaluation doesn't finish or expressions for which the evaluation turns into errors).
Then, there are an exponential number of functions from A
to B
. More exactly |B| ^ |A|
.
Thus, there are 3^3 = 27
functions of type Bool -> Bool
.
Now, for the second part of the question: function starting from bottom can be only 2: the one constantly returning True
and the one constantly returning False
. Then you have to add the number of functions from {True, False}
to {True, False, bottom}
which is 3^2
. So, in total you'll have 9+2=11
functions.
Edit: Here are the 11 possible functions:
B
is bottom, T
is True
, F
is False
. The last row represents the const True
and the const False
functions while the first three rows represent functions testing the value of the argument. That is why the first three rows map B
to B
: testing the value of bottom cannot result in anything else but bottom.
I hope it is clearer now.
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