{-# LANGUAGE TemplateHaskell, TypeApplications, TypeFamilies, TypeOperators,
GADTs, ScopedTypeVariables, DeriveDataTypeable, UndecidableInstances,
DataKinds, PolyKinds, StandaloneKindSignatures #-}
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)
Sing a
SFalse %&& :: Sing a -> Sing b -> Sing (a && b)
%&& Sing b
_ = Sing (a && b)
SBool 'False
SFalse
Sing a
STrue %&& Sing b
a = Sing b
Sing (a && b)
a
infixr 3 %&&
$(genDefunSymbols [''(&&)])
instance SingI (&&@#@$) where
sing :: Sing (&&@#@$)
sing = SingFunction2 (&&@#@$) -> Sing (&&@#@$)
forall a1 a2 b (f :: a1 ~> (a2 ~> b)). SingFunction2 f -> Sing f
singFun2 forall (a :: Bool) (b :: Bool). Sing a -> Sing b -> Sing (a && b)
SingFunction2 (&&@#@$)
(%&&)
instance SingI x => SingI ((&&@#@$$) x) where
sing :: Sing ((&&@#@$$) x)
sing = SingFunction1 ((&&@#@$$) x) -> Sing ((&&@#@$$) x)
forall a1 b (f :: a1 ~> b). 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)
Sing a
SFalse %|| :: Sing a -> Sing b -> Sing (a || b)
%|| Sing b
a = Sing b
Sing (a || b)
a
Sing a
STrue %|| Sing b
_ = Sing (a || b)
SBool 'True
STrue
infixr 2 %||
$(genDefunSymbols [''(||)])
instance SingI (||@#@$) where
sing :: Sing (||@#@$)
sing = SingFunction2 (||@#@$) -> Sing (||@#@$)
forall a1 a2 b (f :: a1 ~> (a2 ~> b)). SingFunction2 f -> Sing f
singFun2 forall (a :: Bool) (b :: Bool). Sing a -> Sing b -> Sing (a || b)
SingFunction2 (||@#@$)
(%||)
instance SingI x => SingI ((||@#@$$) x) where
sing :: Sing ((||@#@$$) x)
sing = SingFunction1 ((||@#@$$) x) -> Sing ((||@#@$$) x)
forall a1 b (f :: a1 ~> b). 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 Sing a
SFalse = Sing (Not a)
SBool 'True
STrue
sNot Sing a
STrue = Sing (Not a)
SBool 'False
SFalse
$(genDefunSymbols [''Not])
instance SingI NotSym0 where
sing :: Sing NotSym0
sing = SingFunction1 NotSym0 -> Sing NotSym0
forall a1 b (f :: a1 ~> b). 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 Sing a
STrue Sing b
b Sing c
_ = Sing b
Sing (If a b c)
b
sIf Sing a
SFalse Sing b
_ Sing c
c = Sing c
Sing (If a b c)
c