{-# LANGUAGE KindSignatures, GADTs, TypeFamilies, TypeOperators, MultiParamTypeClasses, DataKinds #-} import Control.Applicative import Data.Traversable (Traversable) class (Applicative f, Traversable f) => Dim f class Shapely (fs :: [* -> *]) instance Shapely '[] instance (Dim f, Shapely fs) => Shapely (f ': fs) ------------------------------------- -- Hypercuboid datatype ------------------------------------- data Hyper :: [* -> *] -> * -> * where Scalar :: a -> Hyper '[] a Prism :: (Dim f, Shapely fs) => Hyper fs (f a) -> Hyper (f ': fs) a instance Functor (Hyper fs) where fmap f (Scalar a) = Scalar $ f a fmap f (Prism p) = Prism $ fmap (fmap f) p instance Applicative (Hyper fs) where pure a = undefined {- `pure a = Scalar a` gives: Couldn't match type ‘fs’ with ‘'[]’ ‘fs’ is a rigid type variable bound by the instance declaration Expected type: Hyper fs a Actual type: Hyper '[] a -} main = print 42