on ddb8ea2 help sign in
hakyll/src/Hakyll/Core/CompiledItem.hs
39 lines 1.1 kB history raw
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 (e.g. we want
3-- a 'Typeable' instance to perform type-safe casts).
4--
5{-# LANGUAGE ExistentialQuantification #-}
6module Hakyll.Core.CompiledItem
7 ( CompiledItem (..)
8 , compiledItem
9 , unCompiledItem
10 ) where
12import Data.Binary (Binary)
13import Data.Typeable (Typeable, cast)
15import Hakyll.Core.Writable
17-- | Box type for a compiled item
18--
19data CompiledItem = forall a. (Binary a, Typeable a, Writable a)
20 => CompiledItem a
22instance Writable CompiledItem where
23 write p (CompiledItem x) = write p x
25-- | Box a value into a 'CompiledItem'
26--
27compiledItem :: (Binary a, Typeable a, Writable a)
28 => a
29 -> CompiledItem
30compiledItem = CompiledItem
32-- | Unbox a value from a 'CompiledItem'
33--
34unCompiledItem :: (Binary a, Typeable a, Writable a)
35 => CompiledItem
36 -> a
37unCompiledItem (CompiledItem x) = case cast x of
38 Just x' -> x'
39 Nothing -> error "unCompiledItem: Unsupported type"