{-# language TypeFamilies, DataKinds, UndecidableSuperClasses, UndecidableInstances, TypeFamilyDependencies, QuantifiedConstraints #-} module M where import GHC.TypeLits data FArray (n :: Nat) instance Num (FArray n) class Tensor r where type TensorOf (n :: Nat) r = t | t -> n r instance Tensor Float where type TensorOf n Float = FArray n class c (TensorOf n r) => CTensorOf c n r instance c (TensorOf n r) => CTensorOf c n r foo :: (forall n. CTensorOf Num n r) => TensorOf n r -> TensorOf n r foo x = x bar :: FArray n -> FArray n bar x = foo x