{-# LANGUAGE CPP #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Data.Parameterized.WithRepr(IsRepr(..)) where
import Data.Parameterized.Classes
#ifdef UNSAFE_OPS
import Data.Constraint(Dict(..))
import Unsafe.Coerce(unsafeCoerce)
import Data.Parameterized.NatRepr (NatRepr)
import Data.Parameterized.SymbolRepr (SymbolRepr)
import Data.Parameterized.Peano (PeanoRepr)
import Data.Parameterized.Context(Assignment)
import Data.Parameterized.List(List)
#else
import Data.Parameterized.Peano (PeanoRepr,PeanoView(..))
#endif
import Data.Parameterized.BoolRepr
class IsRepr (f :: k -> *) where
withRepr :: f a -> (KnownRepr f a => r) -> r
#ifdef UNSAFE_OPS
withRepr f a
si KnownRepr f a => r
r = case f a -> Dict (KnownRepr f a)
forall k (f :: k -> *) (a :: k).
IsRepr f =>
f a -> Dict (KnownRepr f a)
reprInstance f a
si of
Dict (KnownRepr f a)
Dict -> r
KnownRepr f a => r
r
reprInstance :: forall f a . IsRepr f => f a -> Dict (KnownRepr f a)
reprInstance :: f a -> Dict (KnownRepr f a)
reprInstance f a
s = (KnownRepr f a => Dict (KnownRepr f a)) -> Dict (KnownRepr f a)
with_repr KnownRepr f a => Dict (KnownRepr f a)
forall (a :: Constraint). a => Dict a
Dict
where
with_repr :: (KnownRepr f a => Dict (KnownRepr f a)) -> Dict (KnownRepr f a)
with_repr :: (KnownRepr f a => Dict (KnownRepr f a)) -> Dict (KnownRepr f a)
with_repr KnownRepr f a => Dict (KnownRepr f a)
si = DI f a -> f a -> Dict (KnownRepr f a)
forall a b. a -> b
unsafeCoerce ((KnownRepr f a => Dict (KnownRepr f a)) -> DI f a
forall k (f :: k -> *) (a :: k).
(KnownRepr f a => Dict (KnownRepr f a)) -> DI f a
Don'tInstantiate KnownRepr f a => Dict (KnownRepr f a)
si) f a
s
newtype DI f a = Don'tInstantiate (KnownRepr f a => Dict (KnownRepr f a))
#endif
#ifdef UNSAFE_OPS
instance IsRepr NatRepr
instance IsRepr SymbolRepr
instance IsRepr PeanoRepr
instance IsRepr BoolRepr
instance IsRepr f => IsRepr (List f)
instance IsRepr f => IsRepr (Assignment f)
#else
instance IsRepr PeanoRepr where
withRepr ZRepr f = f
withRepr (SRepr m) f = withRepr m f
instance IsRepr BoolRepr where
withRepr TrueRepr f = f
withRepr FalseRepr f = f
#endif