1-- | A module containing a box datatype representing a compiled item. This
2-- item can be of any type, given that a few restrictions hold:
4-- * we need a 'Typeable' instance to perform type-safe casts;
6-- * we need a 'Binary' instance so we can serialize these items to the cache;
8-- * we need a 'Writable' instance so the results can be saved.
10{-# LANGUAGE ExistentialQuantification, DeriveDataTypeable #-}
11module Hakyll.Core.CompiledItem
17import Data.Binary (Binary)
18import Data.Typeable (Typeable, cast, typeOf)
19import Data.Maybe (fromMaybe)
21import Hakyll.Core.Writable
23-- | Box type for a compiled item
25data CompiledItem = forall a. (Binary a, Typeable a, Writable a)
29instance Writable CompiledItem where
30 write p (CompiledItem x) = write p x
32-- | Box a value into a 'CompiledItem'
34compiledItem :: (Binary a, Typeable a, Writable a)
37compiledItem = CompiledItem
39-- | Unbox a value from a 'CompiledItem'
41unCompiledItem :: (Binary a, Typeable a, Writable a)
44unCompiledItem (CompiledItem x) = fromMaybe error' $ cast x
46 error' = error $ "Hakyll.Core.CompiledItem.unCompiledItem: "
47 ++ "unsupported type (got " ++ show (typeOf x) ++ ")"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list