Skip to content

Instantly share code, notes, and snippets.

@mmynsted
Created January 27, 2021 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmynsted/40d0d88d7fc67b69e1790c11aa95402e to your computer and use it in GitHub Desktop.
Save mmynsted/40d0d88d7fc67b69e1790c11aa95402e to your computer and use it in GitHub Desktop.
-- tsDefaultCompiler :: [Identifier] -> Context String -> Item String -> Compiler (Item String)
-- tsDefaultCompiler
siteIndexCompiler :: Context String -> Item String -> Compiler (Item String)
siteIndexCompiler ctx =
loadAndApplyTemplate "templates/site-index.html" ctx
>=> defaultCompiler ctx
sitePageCompiler :: Context String -> Item String -> Compiler (Item String)
sitePageCompiler ctx =
loadAndApplyTemplate "templates/site-page.html" ctx
>=> defaultCompiler ctx
defaultCompiler :: Context String -> Item String -> Compiler (Item String)
defaultCompiler ctx =
loadAndApplyTemplate "templates/default.html" ctx
>=> cleanAndRelUrls
@mmynsted
Copy link
Author

tsDefaultCompiler ::
    [Identifier] ->
    Context String ->
    Item String ->
    Compiler (Item String)
tsDefaultCompiler ts ctx =
    foldM
        (\acc b -> acc >>= loadAndApplyTemplate b ctx)
        (empty :: Compiler (Item String))
        ts

siteIndexCompiler ::
    Context String ->
    Item String ->
    Compiler (Item String)
siteIndexCompiler ctx =
    tsDefaultCompiler ["templates/site-index.html", "templates/default.html"] ctx
        >=> cleanAndRelUrls

sitePageCompiler :: Context String -> Item String -> Compiler (Item String)
sitePageCompiler ctx =
    loadAndApplyTemplate "templates/site-page.html" ctx
        >=> defaultCompiler ctx

defaultCompiler :: Context String -> Item String -> Compiler (Item String)
defaultCompiler ctx =
    loadAndApplyTemplate "templates/default.html" ctx
        >=> cleanAndRelUrls

@mmynsted
Copy link
Author

Here is error when I attempt to compile

6 of 7] Compiling Compilers        ( src/Compilers.hs, /Users/mmynsted/projects/bytesizedworkbench-hakyll/dist-newstyle/build/x86_64-osx/ghc-8.8.4/bytesizedworkbench-hakyll-0.1.0.0/x/site/build/site/site-tmp/Compilers.o )

src/Compilers.hs:22:5: error:
    • Couldn't match expected type ‘Item String
                                    -> Compiler (Item String)’
                  with actual type ‘Compiler (Compiler (Item String))’
    • Possible cause: ‘foldM’ is applied to too many arguments
      In the expression:
        foldM
          (\ acc b -> acc >>= loadAndApplyTemplate b ctx)
          (empty :: Compiler (Item String))
          ts
      In an equation for ‘tsDefaultCompiler’:
          tsDefaultCompiler ts ctx
            = foldM
                (\ acc b -> acc >>= loadAndApplyTemplate b ctx)
                (empty :: Compiler (Item String))
                ts
   |
22 |     foldM
   |     ^^^^^...

src/Compilers.hs:23:20: error:
    • Couldn't match type ‘Item’ with ‘Compiler’
      Expected type: Compiler (Compiler (Item String))
        Actual type: Compiler (Item String)
    • In the expression: acc >>= loadAndApplyTemplate b ctx
      In the first argument of ‘foldM’, namely
        ‘(\ acc b -> acc >>= loadAndApplyTemplate b ctx)’
      In the expression:
        foldM
          (\ acc b -> acc >>= loadAndApplyTemplate b ctx)
          (empty :: Compiler (Item String))
          ts
   |
23 |         (\acc b -> acc >>= loadAndApplyTemplate b ctx)

@mmynsted
Copy link
Author

If I change the function like this

tsDefaultCompiler ::
    [Identifier] ->
    Context String ->
    Item String ->
    Compiler (Item String)
tsDefaultCompiler ts ctx =
    foldM
        (\acc b -> loadAndApplyTemplate b ctx)
        (empty :: Compiler (Item String))
        ts

Then it compiles but the result is always the empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment