Justin Manley
Justin Manley

Reputation: 258

How to use Hakyll.loadSnapshot without "No instance for (Typeable a0)" error

I'm trying to add some functionality to my site so that I can expose different versions of a post. For example, if my source directory contains

mypost/version/1
mypost/version/2
mypost/version/3

I'd like to copy all of the versions of the post into the generated site, along with a new path mypost/version/latest.

To accomplish this, I compile each version of the post and take a snapshot using saveSnapshot. Then I iterate over everything in the mypost/version directory to find the latest version. Finally, I want to get the compiled snapshot of the latest version and copy it into the mypost/version/latest directory.

In my site generator, I pass the output of loadSnapshot into an item-copying compiler, along the lines of:

loadSnapshotAndCopy :: Snapshot -> Compiler (Item CopyFile)
loadSnapshotAndCopy snapshot = do
  identifier <- getUnderlying
  item <- loadSnapshot identifier snapshot
  provider <- compilerProvider <$> compilerAsk
  makeItem $ CopyFile $ resourceFilePath provider (itemIdentifier item)

However, this produces an error:

    • No instance for (Typeable a0)
        arising from a use of ‘loadSnapshot’
    • In a stmt of a 'do' block:
        item <- loadSnapshot identifier snapshot
      In the expression:
        do identifier <- getUnderlying
           item <- loadSnapshot identifier snapshot
           provider <- compilerProvider <$> compilerAsk
           makeItem
             $ CopyFile $ resourceFilePath provider (itemIdentifier item)
      In an equation for ‘loadSnapshotAndCopy’:
          loadSnapshotAndCopy snapshot
            = do identifier <- getUnderlying
                 item <- loadSnapshot identifier snapshot
                 provider <- compilerProvider <$> compilerAsk
                 ....
    |
248 |   item <- loadSnapshot identifier snapshot
    |           ^^^^^^^^^^^^

The type of loadSnapshot is loadSnapshot :: (Binary a, Typeable a) => Identifier -> Snapshot -> Compiler (Item a), so I guess there's a constraint that the compiler is unable to satisfy for some reason. How can get around this in order to use loadSnapshot?

Upvotes: 1

Views: 65

Answers (0)

Related Questions