module Data.Vector.FunctorLazy.Common
where
import GHC.Prim
import Unsafe.Coerce
import Data.Monoid hiding (Any)
data LazyBox = LazyBox
{ lazyc :: !Int
, lazyb :: Any
}
mkLazyBox :: a -> LazyBox
mkLazyBox a = LazyBox
{ lazyc = 0
, lazyb = unsafeCoerce a
}
data LazyController = LazyController
{ funcL :: [Any]
, funcC :: !Int
}
instance Monoid LazyController where
mempty = LazyController [] 0
mappend a b = LazyController
{ funcL = funcL a ++ funcL b
, funcC = funcC a + funcC b
}
appList :: Any -> [Any] -> a
appList box xs = foldr (\f a -> (unsafeCoerce f) a) (unsafeCoerce box) xs