module Hakyll.Core.CompiledItem
( CompiledItem (..)
, compiledItem
, unCompiledItem
) where
import Data.Binary (Binary)
import Data.Typeable (Typeable, cast, typeOf)
import Data.Maybe (fromMaybe)
import Hakyll.Core.Writable
data CompiledItem = forall a. (Binary a, Typeable a, Writable a)
=> CompiledItem a
deriving (Typeable)
instance Writable CompiledItem where
write p (CompiledItem x) = write p x
compiledItem :: (Binary a, Typeable a, Writable a)
=> a
-> CompiledItem
compiledItem = CompiledItem
unCompiledItem :: (Binary a, Typeable a, Writable a)
=> CompiledItem
-> a
unCompiledItem (CompiledItem x) = fromMaybe error' $ cast x
where
error' = error $ "Hakyll.Core.CompiledItem.unCompiledItem: "
++ "unsupported type (got " ++ show (typeOf x) ++ ")"