{-# LANGUAGE Safe #-}
{-# LANGUAGE DeriveGeneric #-}
module Stype.Categorical.Binary (
Binary(..)
, toBool
, toInt
, fromBool
) where
import GHC.Generics ( Generic )
data Binary = Zero | One deriving ( Binary -> Binary -> Bool
(Binary -> Binary -> Bool)
-> (Binary -> Binary -> Bool) -> Eq Binary
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Binary -> Binary -> Bool
$c/= :: Binary -> Binary -> Bool
== :: Binary -> Binary -> Bool
$c== :: Binary -> Binary -> Bool
Eq, Eq Binary
Eq Binary
-> (Binary -> Binary -> Ordering)
-> (Binary -> Binary -> Bool)
-> (Binary -> Binary -> Bool)
-> (Binary -> Binary -> Bool)
-> (Binary -> Binary -> Bool)
-> (Binary -> Binary -> Binary)
-> (Binary -> Binary -> Binary)
-> Ord Binary
Binary -> Binary -> Bool
Binary -> Binary -> Ordering
Binary -> Binary -> Binary
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Binary -> Binary -> Binary
$cmin :: Binary -> Binary -> Binary
max :: Binary -> Binary -> Binary
$cmax :: Binary -> Binary -> Binary
>= :: Binary -> Binary -> Bool
$c>= :: Binary -> Binary -> Bool
> :: Binary -> Binary -> Bool
$c> :: Binary -> Binary -> Bool
<= :: Binary -> Binary -> Bool
$c<= :: Binary -> Binary -> Bool
< :: Binary -> Binary -> Bool
$c< :: Binary -> Binary -> Bool
compare :: Binary -> Binary -> Ordering
$ccompare :: Binary -> Binary -> Ordering
$cp1Ord :: Eq Binary
Ord, (forall x. Binary -> Rep Binary x)
-> (forall x. Rep Binary x -> Binary) -> Generic Binary
forall x. Rep Binary x -> Binary
forall x. Binary -> Rep Binary x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Binary x -> Binary
$cfrom :: forall x. Binary -> Rep Binary x
Generic )
instance Show Binary where
show :: Binary -> String
show Binary
x =
case Binary
x of
Binary
Zero -> String
"0"
Binary
One -> String
"1"
toBool :: Binary -> Bool
toBool :: Binary -> Bool
toBool Binary
Zero = Bool
False
toBool Binary
One = Bool
True
toInt :: Binary -> Int
toInt :: Binary -> Int
toInt Binary
Zero = Int
0
toInt Binary
One = Int
1
fromBool :: Bool -> Binary
fromBool :: Bool -> Binary
fromBool Bool
True = Binary
One
fromBool Bool
False = Binary
Zero