From 365e7e07af88ad9924fac9be85a9aadcaec7845c Mon Sep 17 00:00:00 2001 From: depsterr Date: Sat, 9 Dec 2023 15:41:39 +0100 Subject: [PATCH] highlighting --- _config.yml | 2 + _posts/2022-12-10-why-be-pure.md | 12 ++--- assets/css/main.scss | 75 ++++++++++++++++++++++++++++++++ deps.nix | 1 + 4 files changed, 84 insertions(+), 6 deletions(-) diff --git a/_config.yml b/_config.yml index a1dbeac..ee40251 100644 --- a/_config.yml +++ b/_config.yml @@ -21,6 +21,8 @@ katex: rendering_options: throw_error: true +highlighter: rouge + kramdown: math_engine: katex math_engine_opts: diff --git a/_posts/2022-12-10-why-be-pure.md b/_posts/2022-12-10-why-be-pure.md index 287a875..815b443 100644 --- a/_posts/2022-12-10-why-be-pure.md +++ b/_posts/2022-12-10-why-be-pure.md @@ -12,7 +12,7 @@ Newcomers to Haskell are often told that Haskell is "pure", or that it is "mathe Before we get into the why, we have to get into the what. Haskell is a purely functional language, but what does that mean? Purity tells us that functions in Haskell behave like mathematical functions. That is, functions in Haskell must always give eqaul output for equal input. In mathematics we'd hope that if we have a function $$f$$, and two values $$x$$ and $$y$$ such that $$x = y$$ then $$f(x) = f(y)$$ and the same is true for Haskell. This is the reason that you are not allowed to modify the value of variables in Haskell as you are in other programming languages such as Python. Consider the following Python program: -```python +```py n = 0 def f(x): @@ -54,7 +54,7 @@ map f (x:xs) = f x : map f xs Second, recall how lists are represented in Haskell. When we write `[1,2,3]`, this is shorthand for `1 : (2 : (3 : []))`. Now we can start using our equalities! The definition of `map` tells us that `map f (x : xs) = f x : map f xs`, thus `map (+1) (1 : 2 : 3 : []) = (+1) 1 : map (+1) (2 : 3 : [])` Continuing this reasoning yields us the following: -``` +```hs [map (+1) (1 : 2 : 3 : [])] = (+1) 1 : [map (+1) (2 : 3 : [])] = (+1) 1 : (+1) 2 : [map (+1) (3 : [])] @@ -63,7 +63,7 @@ Second, recall how lists are represented in Haskell. When we write `[1,2,3]`, th In each step the code within `[]` is replaced using the same equality rule. For the final step we look at the first case of map telling us that `map f [] = []` -``` +```hs = (+1) 1 : (+1) 2 : (+1) 3 : [] = 2 : 3 : 4 : [] = [2,3,4] @@ -75,7 +75,7 @@ While this is mildly interesting, it's not very useful as we could have simply a A more exciting example is proving that `map f (map g xs) = map (f . g) xs` for all functions `f`, `g`, and lists `xs`. Recall the definition of `.` -``` +```hs (.) :: (b -> c) -> (a -> b) -> (a -> c) (.) f g x = f (g x) ``` @@ -84,7 +84,7 @@ That is, `f . g` is a function that first applies `g` to an input and then appli First, consider the `[]` case: -``` +```hs map f (map g []) = map f [] = [] @@ -93,7 +93,7 @@ First, consider the `[]` case: Secondly, consider the `x : xs` case, assuming that the property holds for `xs`: -``` +```hs map f (map g (x : xs)) = map f (g x : map g xs) = f (g x) : map f (map g xs) diff --git a/assets/css/main.scss b/assets/css/main.scss index 4a4c742..a8888ae 100644 --- a/assets/css/main.scss +++ b/assets/css/main.scss @@ -186,3 +186,78 @@ table { table { border-collapse: collapse; } + +// https://github.com/daveyarwood/gruvbox-pygments/tree/master +.highlight .hll { background-color: #ffffcc } +.highlight { background: #282828; color: #ebdbb2; background-color: #282828 } +.highlight .c { color: #928374; font-style: italic; background-color: #282828 } /* Comment */ +.highlight .err { color: #ebdbb2; background-color: #282828 } /* Error */ +.highlight .esc { color: #ebdbb2; background-color: #282828 } /* Escape */ +.highlight .g { color: #ebdbb2; background-color: #282828 } /* Generic */ +.highlight .k { color: #fe8019; background-color: #282828 } /* Keyword */ +.highlight .l { color: #ebdbb2; background-color: #282828 } /* Literal */ +.highlight .n { color: #ebdbb2; background-color: #282828 } /* Name */ +.highlight .o { color: #fe8019; background-color: #282828 } /* Operator */ +.highlight .x { color: #ebdbb2; background-color: #282828 } /* Other */ +.highlight .p { color: #ebdbb2; background-color: #282828 } /* Punctuation */ +.highlight .ch { color: #928374; font-style: italic; background-color: #282828 } /* Comment.Hashbang */ +.highlight .cm { color: #928374; font-style: italic; background-color: #282828 } /* Comment.Multiline */ +.highlight .cp { color: #8ec07c; background-color: #282828 } /* Comment.Preproc */ +.highlight .c1 { color: #928374; font-style: italic; background-color: #282828 } /* Comment.Single */ +.highlight .cs { color: #928374; font-style: italic; background-color: #282828 } /* Comment.Special */ +.highlight .gd { color: #282828; background-color: #fb4934 } /* Generic.Deleted */ +.highlight .ge { color: #83a598; text-decoration: underline; background-color: #282828 } /* Generic.Emph */ +.highlight .gr { color: #ebdbb2; font-weight: bold; background-color: #fb4934 } /* Generic.Error */ +.highlight .gh { color: #b8bb26; font-weight: bold; background-color: #282828 } /* Generic.Heading */ +.highlight .gi { color: #282828; background-color: #b8bb26 } /* Generic.Inserted */ +.highlight .go { color: #504945; background-color: #282828 } /* Generic.Output */ +.highlight .gp { color: #ebdbb2; background-color: #282828 } /* Generic.Prompt */ +.highlight .gs { color: #ebdbb2; background-color: #282828 } /* Generic.Strong */ +.highlight .gu { color: #b8bb26; font-weight: bold; background-color: #282828 } /* Generic.Subheading */ +.highlight .gt { color: #ebdbb2; font-weight: bold; background-color: #fb4934 } /* Generic.Traceback */ +.highlight .kc { color: #fe8019; background-color: #282828 } /* Keyword.Constant */ +.highlight .kd { color: #fe8019; background-color: #282828 } /* Keyword.Declaration */ +.highlight .kn { color: #fe8019; background-color: #282828 } /* Keyword.Namespace */ +.highlight .kp { color: #fe8019; background-color: #282828 } /* Keyword.Pseudo */ +.highlight .kr { color: #fe8019; background-color: #282828 } /* Keyword.Reserved */ +.highlight .kt { color: #fabd2f; background-color: #282828 } /* Keyword.Type */ +.highlight .ld { color: #ebdbb2; background-color: #282828 } /* Literal.Date */ +.highlight .m { color: #d3869b; background-color: #282828 } /* Literal.Number */ +.highlight .s { color: #b8bb26; background-color: #282828 } /* Literal.String */ +.highlight .na { color: #b8bb26; font-weight: bold; background-color: #282828 } /* Name.Attribute */ +.highlight .nb { color: #fabd2f; background-color: #282828 } /* Name.Builtin */ +.highlight .nc { color: #ebdbb2; background-color: #282828 } /* Name.Class */ +.highlight .no { color: #d3869b; background-color: #282828 } /* Name.Constant */ +.highlight .nd { color: #ebdbb2; background-color: #282828 } /* Name.Decorator */ +.highlight .ni { color: #fabd2f; background-color: #282828 } /* Name.Entity */ +.highlight .ne { color: #fb4934; background-color: #282828 } /* Name.Exception */ +.highlight .nf { color: #fabd2f; background-color: #282828 } /* Name.Function */ +.highlight .nl { color: #fb4934; background-color: #282828 } /* Name.Label */ +.highlight .nn { color: #ebdbb2; background-color: #282828 } /* Name.Namespace */ +.highlight .nx { color: #ebdbb2; background-color: #282828 } /* Name.Other */ +.highlight .py { color: #ebdbb2; background-color: #282828 } /* Name.Property */ +.highlight .nt { color: #fb4934; background-color: #282828 } /* Name.Tag */ +.highlight .nv { color: #ebdbb2; background-color: #282828 } /* Name.Variable */ +.highlight .ow { color: #fe8019; background-color: #282828 } /* Operator.Word */ +.highlight .w { color: #ebdbb2; background-color: #282828 } /* Text.Whitespace */ +.highlight .mb { color: #d3869b; background-color: #282828 } /* Literal.Number.Bin */ +.highlight .mf { color: #d3869b; background-color: #282828 } /* Literal.Number.Float */ +.highlight .mh { color: #d3869b; background-color: #282828 } /* Literal.Number.Hex */ +.highlight .mi { color: #d3869b; background-color: #282828 } /* Literal.Number.Integer */ +.highlight .mo { color: #d3869b; background-color: #282828 } /* Literal.Number.Oct */ +.highlight .sb { color: #b8bb26; background-color: #282828 } /* Literal.String.Backtick */ +.highlight .sc { color: #b8bb26; background-color: #282828 } /* Literal.String.Char */ +.highlight .sd { color: #b8bb26; background-color: #282828 } /* Literal.String.Doc */ +.highlight .s2 { color: #b8bb26; background-color: #282828 } /* Literal.String.Double */ +.highlight .se { color: #b8bb26; background-color: #282828 } /* Literal.String.Escape */ +.highlight .sh { color: #b8bb26; background-color: #282828 } /* Literal.String.Heredoc */ +.highlight .si { color: #b8bb26; background-color: #282828 } /* Literal.String.Interpol */ +.highlight .sx { color: #b8bb26; background-color: #282828 } /* Literal.String.Other */ +.highlight .sr { color: #b8bb26; background-color: #282828 } /* Literal.String.Regex */ +.highlight .s1 { color: #b8bb26; background-color: #282828 } /* Literal.String.Single */ +.highlight .ss { color: #83a598; background-color: #282828 } /* Literal.String.Symbol */ +.highlight .bp { color: #fabd2f; background-color: #282828 } /* Name.Builtin.Pseudo */ +.highlight .vc { color: #ebdbb2; background-color: #282828 } /* Name.Variable.Class */ +.highlight .vg { color: #ebdbb2; background-color: #282828 } /* Name.Variable.Global */ +.highlight .vi { color: #ebdbb2; background-color: #282828 } /* Name.Variable.Instance */ +.highlight .il { color: #d3869b; background-color: #282828 } /* Literal.Number.Integer.Long */ diff --git a/deps.nix b/deps.nix index 457ddfb..1345cb7 100644 --- a/deps.nix +++ b/deps.nix @@ -121,6 +121,7 @@ with pkgs; let cssminify2 json-minify webrick + rouge ]); in [ nodejs ] ++ rubyEnv.gems