1

I'm trying to write a special Hakyll compiler to use a lua script to build my website. I found this function which seams to make what I want :

customWriterCompilerWith :: (WriterOptions -> Pandoc -> IO String)
                         -> ReaderOptions -> WriterOptions
                         -> Compiler (Item String)
customWriterCompilerWith customWriter ropt wopt = do
    body <- getResourceBody
    withItemBody (unsafeCompiler . customWriter wopt) $ readPandocWith ropt body

However, when I try to compile this function, I get this error :

• Couldn't match expected type ‘Item Pandoc’
              with actual type ‘Compiler (Item Pandoc)’
• In the second argument of ‘($)’, namely
    ‘readPandocWith ropt body’

After searching in the Hakyll documentation, there is a difference between the type of readPandocWith in versions 4.6.8.0 and 4.9.8.0 (my version) :

readPandocWith:: ReaderOptions-> Item String-> Item Pandoc -- 4.6.8.0

readPandocWith:: ReaderOptions-> Item String-> Compiler (Item Pandoc) -- 4.9.8.0

I didn't find in the Hakyll documentation a function (whose type should be Compiler (Item Pandoc)-> Item Pandoc) which could help me.

Do you know how to solve this problem ?

Do you know another way to make a custom Hakyll compiler with a LUA script ?

JeanJouX
  • 2,555
  • 1
  • 25
  • 37
  • 1
    There is no such function (it cannot exist); so it isn't the function you want. The actual function you want is `>>= :: Compiler a -> (a -> Compiler b) -> Compiler b`. Or, since you are already using `do` notation, `do { body <- ..; doc <- readPandocWith ropt body; withItemBody (..) doc }`. Aside: I would suggest to familiarize yourself with the more basic abstraction patterns which are employed by nearly every mature Haskell library; this would certainly help you navigate the Haskell ecosystem. – user2407038 Jul 07 '17 at 19:28
  • 1
    @user2407038 Make this an answer. – arrowd Jul 07 '17 at 21:38

1 Answers1

0

As mentioned by @user2407038, the following should work:

customWriterCompilerWith customWriter ropt wopt = do
    body <- getResourceBody
    doc  <- readPandocWith ropt body
    withItemBody (unsafeCompiler . customWriter wopt) doc

To read more about <- (which is syntactic sugar for >>=), I can recommend http://learnyouahaskell.com (the monad chapter).

mb21
  • 34,845
  • 8
  • 116
  • 142
  • I didn't read the Hakyll documentation well enough and I didn't saw that `Compiler` was a monad. I'm very embarrassed. – JeanJouX Aug 02 '17 at 21:48