{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module TensorSafe.Core where
import Data.Kind (Type)
import GHC.TypeLits as N
type family ShapeProduct (s :: [Nat]) :: Nat where
ShapeProduct '[] = 1
ShapeProduct (m ': s) = m N.* (ShapeProduct s)
type family TypeEquals (s1 :: Type) (s2 :: Type) :: Bool where
TypeEquals s s = 'True
TypeEquals _ _ = 'False
type family TypeEquals' s1 s2 :: Type where
TypeEquals' s s = s
TypeEquals' s1 s2 =
TypeError ( 'Text "Couldn't match the type "
':<>: 'ShowType s1
':<>: 'Text " with type "
':<>: 'ShowType s2)
data R (n :: Nat) where
R :: (KnownNat n) => R n
instance KnownNat n => Show (R n) where
show n = show (natVal n)
data L (m :: Nat) (n :: Nat) where
L :: (KnownNat m, KnownNat n) => L m n
instance (KnownNat m, KnownNat n) => Show (L m n) where
show n = show (natVal n)