{-# LANGUAGE TemplateHaskell, TypeApplications, TypeFamilies, TypeOperators,
GADTs, ScopedTypeVariables, DeriveDataTypeable, UndecidableInstances,
DataKinds, PolyKinds #-}
module Data.Singletons.Prelude.Bool (
Sing, SBool(..),
If, sIf,
Not, sNot, type (&&), type (||), (%&&), (%||),
bool_, Bool_, sBool_, Otherwise, sOtherwise,
TrueSym0, FalseSym0,
NotSym0, NotSym1,
type (&&@#@$), type (&&@#@$$), type (&&@#@$$$),
type (||@#@$), type (||@#@$$), type (||@#@$$$),
Bool_Sym0, Bool_Sym1, Bool_Sym2, Bool_Sym3,
OtherwiseSym0
) where
import Data.Singletons.Internal
import Data.Singletons.Prelude.Instances
import Data.Singletons.Promote
import Data.Singletons.Single
import Data.Type.Bool ( If, type (&&), type (||), Not )
$(singletons [d|
bool_ :: a -> a -> Bool -> a
bool_ fls _tru False = fls
bool_ _fls tru True = tru
|])
$(singletonsOnly [d|
otherwise :: Bool
otherwise = True
|])
(%&&) :: Sing a -> Sing b -> Sing (a && b)
SFalse %&& :: Sing a -> Sing b -> Sing (a && b)
%&& _ = Sing (a && b)
SBool 'False
SFalse
STrue %&& a :: Sing b
a = Sing b
Sing (a && b)
a
infixr 3 %&&
$(genDefunSymbols [''(&&)])
instance SingI (&&@#@$) where
sing :: Sing (&&@#@$)
sing = SingFunction2 (&&@#@$) -> Sing (&&@#@$)
forall k2 k3 k (f :: k2 ~> (k3 ~> k)). SingFunction2 f -> Sing f
singFun2 SingFunction2 (&&@#@$)
forall (a :: Bool) (b :: Bool). Sing a -> Sing b -> Sing (a && b)
(%&&)
instance SingI x => SingI ((&&@#@$$) x) where
sing :: Sing ((&&@#@$$) x)
sing = SingFunction1 ((&&@#@$$) x) -> Sing ((&&@#@$$) x)
forall k1 k (f :: k1 ~> k). SingFunction1 f -> Sing f
singFun1 (SingI x => Sing x
forall k (a :: k). SingI a => Sing a
sing @x Sing x -> Sing t -> Sing (x && t)
forall (a :: Bool) (b :: Bool). Sing a -> Sing b -> Sing (a && b)
%&&)
(%||) :: Sing a -> Sing b -> Sing (a || b)
SFalse %|| :: Sing a -> Sing b -> Sing (a || b)
%|| a :: Sing b
a = Sing b
Sing (a || b)
a
STrue %|| _ = Sing (a || b)
SBool 'True
STrue
infixr 2 %||
$(genDefunSymbols [''(||)])
instance SingI (||@#@$) where
sing :: Sing (||@#@$)
sing = SingFunction2 (||@#@$) -> Sing (||@#@$)
forall k2 k3 k (f :: k2 ~> (k3 ~> k)). SingFunction2 f -> Sing f
singFun2 SingFunction2 (||@#@$)
forall (a :: Bool) (b :: Bool). Sing a -> Sing b -> Sing (a || b)
(%||)
instance SingI x => SingI ((||@#@$$) x) where
sing :: Sing ((||@#@$$) x)
sing = SingFunction1 ((||@#@$$) x) -> Sing ((||@#@$$) x)
forall k1 k (f :: k1 ~> k). SingFunction1 f -> Sing f
singFun1 (SingI x => Sing x
forall k (a :: k). SingI a => Sing a
sing @x Sing x -> Sing t -> Sing (x || t)
forall (a :: Bool) (b :: Bool). Sing a -> Sing b -> Sing (a || b)
%||)
sNot :: Sing a -> Sing (Not a)
sNot :: Sing a -> Sing (Not a)
sNot SFalse = Sing (Not a)
SBool 'True
STrue
sNot STrue = Sing (Not a)
SBool 'False
SFalse
$(genDefunSymbols [''Not])
instance SingI NotSym0 where
sing :: Sing NotSym0
sing = SingFunction1 NotSym0 -> Sing NotSym0
forall k1 k (f :: k1 ~> k). SingFunction1 f -> Sing f
singFun1 forall (a :: Bool). Sing a -> Sing (Not a)
SingFunction1 NotSym0
sNot
sIf :: Sing a -> Sing b -> Sing c -> Sing (If a b c)
sIf :: Sing a -> Sing b -> Sing c -> Sing (If a b c)
sIf STrue b :: Sing b
b _ = Sing b
Sing (If a b c)
b
sIf SFalse _ c :: Sing c
c = Sing c
Sing (If a b c)
c