1--------------------------------------------------------------------------------
2-- | A module containing a box datatype representing a compiled item. This
3-- item can be of any type, given that a few restrictions hold:
5-- * we need a 'Typeable' instance to perform type-safe casts;
7-- * we need a 'Binary' instance so we can serialize these items to the cache;
9-- * we need a 'Writable' instance so the results can be saved.
10{-# LANGUAGE DeriveDataTypeable #-}
11{-# LANGUAGE ExistentialQuantification #-}
12module Hakyll.Core.CompiledItem
19--------------------------------------------------------------------------------
20import Data.Binary (Binary)
21import Data.Maybe (fromMaybe)
22import Data.Typeable (Typeable, cast, typeOf)
25--------------------------------------------------------------------------------
26import Hakyll.Core.Writable
29--------------------------------------------------------------------------------
30-- | Box type for a compiled item
32data CompiledItem = forall a. (Binary a, Typeable a, Writable a)
37--------------------------------------------------------------------------------
38instance Writable CompiledItem where
39 write p (CompiledItem x) = write p x
42--------------------------------------------------------------------------------
43-- | Box a value into a 'CompiledItem'
44compiledItem :: (Binary a, Typeable a, Writable a) => a -> CompiledItem
45compiledItem = CompiledItem
48--------------------------------------------------------------------------------
49-- | Unbox a value from a 'CompiledItem'
50unCompiledItem :: (Binary a, Typeable a, Writable a) => CompiledItem -> a
51unCompiledItem (CompiledItem x) = fromMaybe error' $ cast x
54 "Hakyll.Core.CompiledItem.unCompiledItem: " ++
55 "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