Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ordering of Bool types (i.e. True > False) - Why? [duplicate]

Tags:

haskell

Can someone please explain the following output?

Prelude> compare True False
GT
it :: Ordering
Prelude> compare False True
LT
it :: Ordering

Why are Bool type values ordered in Haskell - especially, since we can demonstrate that values of True and False are not exactly 1 and 0 (unlike many other languages)?

like image 879
archilius Avatar asked Nov 13 '15 12:11

archilius


1 Answers

This is how the derived instance of Ord works:

data D = A | B | C deriving Ord

Given that datatype, we get C > B > A. Bool is defined as False | True, and it kind of makes sense when you look at other examples such as:

  • Maybe a = Nothing | Just a
  • Either a b = Left a | Right b

In each of the case having "some" ("truthy") value is greater than having no values at all (or having "left" or "bad" or "falsy" value).

like image 128
Bartek Banachewicz Avatar answered Nov 15 '22 10:11

Bartek Banachewicz