{-|
Module      : Stype binary 
Description : Statistical types
Copyright   : (c) NoviSci, Inc 2020
License     : BSD3
Maintainer  : bsaul@novisci.com

-}

{-# LANGUAGE Safe #-}
{-# LANGUAGE DeriveGeneric #-}

module Stype.Categorical.Binary (
    Binary(..)
  , toBool
  , toInt
  , fromBool
) where

import GHC.Generics             ( Generic )

{- | Binary Type -}
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"

-- | Convert a @Binary@ to @Bool@.
toBool :: Binary -> Bool 
toBool :: Binary -> Bool
toBool Binary
Zero = Bool
False 
toBool Binary
One  = Bool
True 

-- | Convert @Binary@ to @Int@.
toInt :: Binary -> Int 
toInt :: Binary -> Int
toInt Binary
Zero = Int
0
toInt Binary
One  = Int
1

-- | Create a @Binary@ from a @Bool@. 
fromBool :: Bool -> Binary
fromBool :: Bool -> Binary
fromBool Bool
True  = Binary
One
fromBool Bool
False = Binary
Zero