@@ -1,6 +1,6 @@
1-- | A store for stroing and retreiving items
1-- | A store for stroing and retreiving items
3−{-# LANGUAGE ExistentialQuantification #-}
3+{-# LANGUAGE ExistentialQuantification, ScopedTypeVariables #-}
4module Hakyll.Core.Store
4module Hakyll.Core.Store
6 , StoreGet (..)
6 , StoreGet (..)
@@ -17,7 +17,7 @@ import Data.Map (Map)
17import qualified Data.Map as M
17import qualified Data.Map as M
19import Data.Binary (Binary, encodeFile, decodeFile)
19import Data.Binary (Binary, encodeFile, decodeFile)
20−import Data.Typeable (Typeable, cast)
20+import Data.Typeable (Typeable, TypeRep, cast, typeOf)
22import Hakyll.Core.Identifier
22import Hakyll.Core.Identifier
23import Hakyll.Core.Util.File
23import Hakyll.Core.Util.File
@@ -30,8 +30,8 @@ data Storable = forall a. (Binary a, Typeable a) => Storable a
31data StoreGet a = Found a
31data StoreGet a = Found a
32 | NotFound
32 | NotFound
33− | WrongType
33+ | WrongType TypeRep TypeRep
34− deriving (Show, Eq, Ord)
34+ deriving (Show, Eq)
36-- | Data structure used for the store
36-- | Data structure used for the store
@@ -79,7 +79,7 @@ storeSet store name identifier value = do
80-- | Load an item
80-- | Load an item
82−storeGet :: (Binary a, Typeable a)
82+storeGet :: forall a. (Binary a, Typeable a)
83 => Store -> String -> Identifier -> IO (StoreGet a)
83 => Store -> String -> Identifier -> IO (StoreGet a)
84storeGet store name identifier = do
84storeGet store name identifier = do
85 -- First check the in-memory map
85 -- First check the in-memory map
@@ -87,7 +87,7 @@ storeGet store name identifier = do
87 case M.lookup path map' of
87 case M.lookup path map' of
88 -- Found in the in-memory map
88 -- Found in the in-memory map
89 Just (Storable s) -> return $ case cast s of
89 Just (Storable s) -> return $ case cast s of
90− Nothing -> WrongType
90+ Nothing -> WrongType (typeOf s) $ typeOf (undefined :: a)
91 Just s' -> Found s'
91 Just s' -> Found s'
92 -- Not found in the map, try the filesystem
92 -- Not found in the map, try the filesystem
93 Nothing -> do
93 Nothing -> do