module Data.Array.Comfort.Construct.Private where import qualified Data.Array.Comfort.Shape as Shape import qualified Control.Monad.Trans.Writer as MW import qualified Control.Monad.Trans.Class as MT newtype T tag a i = Cons (MW.WriterT [a] (Shape.Construction tag) i) instance Functor (T tag a) where fmap f (Cons w) = Cons (fmap f w) instance Applicative (T tag a) where pure i = Cons (pure i) Cons f <*> Cons w = Cons (f<*>w) element :: a -> T tag a (Shape.ConsIndex tag) element a = Cons $ MW.tell [a] >> MT.lift Shape.consIndex run :: T tag a ixs -> (ixs, (Shape.Constructed tag, [a])) run (Cons mw) = case Shape.construct $ MW.runWriterT mw of (sh,(ixs,xs)) -> (ixs, (sh,xs))