conditional finality https://blog.youwen.dev/atom.xml Youwen Wu youwenw@gmail.com 2024-05-25T12:00:00Z a haskellian blog https://blog.youwen.dev/a-haskellian-blog.html 2024-05-25T00:00:00Z 2024-05-25T12:00:00Z

a haskellian blog

a purely functional...blog?

2024-05-25
(last updated: 2024-05-25T12:00:00Z)

Welcome! This is the first post on conditional finality and also one that tests all of the features.

conditional finality

A monad is just a monoid in the category of endofunctors, what’s the problem?

haskell?

This entire blog is generated with hakyll. It’s a library for generating static sites for Haskell, a purely functional programming language. It’s a library because it doesn’t come with as many batteries included as tools like Hugo or Astro. You set up most of the site yourself by calling the library from Haskell.

Here’s a brief excerpt:

main :: IO ()
main = hakyllWith config $ do
    forM_
        [ "CNAME"
        , "favicon.ico"
        , "robots.txt"
        , "_config.yml"
        , "images/*"
        , "out/*"
        , "fonts/*"
        ]
        $ \f -> match f $ do
            route idRoute
            compile copyFileCompiler

The code highlighting is also generated by hakyll.


why?

Haskell is a purely functional language with no mutable state. Its syntax actually makes it pretty elegant for declaring routes and “rendering” pipelines.

  1. Haskell is cool.
  2. It comes with enough features that I don’t feel like I have to build everything from scratch.
  3. It comes with Pandoc, a Haskell library for converting between markdown formats. It’s probably more powerful than anything you could do in nodejs. It renders all of the markdown to HTML as well as the math.
    1. It supports KaTeX as well as MathML. I’m a little disappointed with the KaTeX though. It doesn’t directly render it, but simply injects the KaTeX files and renders it client-side.

speaking of math

We can have math inline, like so: ex2dx=π\int_{-\infty}^\infty \, e^{-x^2}\,dx = \sqrt{\pi}. This site ships semantic MathML math with its HTML, and the MathJax script to the client.

It’d be nice if MathML could just be used and supported across all browsers, but unfortunately we still aren’t quite there yet. Firefox is the only one where everything looks 80% of the way to LaTeX. On Safari and Chrome, even simple equations like π\sqrt{\pi} render improperly.

Pros of MathML:

  • A little more accessible
  • Can be rendered without additional stylesheets. I just installed the Latin Modern font, but this isn’t even really necessary
  • Built-in to most browsers (#UseThePlatform)

Cons:

  • Isn’t fully standardized. Might look different on different browsers
  • Rendering quality isn’t as good as KaTeX

This site has MathJax render all of the math so it looks nice and standardized across browsers, but the math still displays regardless (like say if MathJax couldn’t load due to slow network) because of MathML. Best of both worlds.

Let’s try it now. Here’s a simple theorem:

an+bncn{a,b,c}n3 a^n + b^n \ne c^n \, \forall\,\left\{ a,\,b,\,c \right\} \in \mathbb{Z} \land n \ge 3

The proof is trivial and will be left as an exercise to the reader.

seems a little overengineered

Probably is. Not as much as the old one, though.

]]>