Skip to content

Instantly share code, notes, and snippets.

@khuldraeseth
khuldraeseth / MonadsAndMTL.hs
Last active July 17, 2023 04:19
The Haskell rite of passage
{-
A Haskell source file begins with zero or more file-scope pragmas that tell tools how to treat the file.
Pragmas look like multiline comments `{- ... -}` that begin and end with `#`.
The LANGUAGE pragma is a common one. it enables language extensions.
Oh, yeah. Haskell allows nested multiline comments, by the way.
-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
@khuldraeseth
khuldraeseth / eecs281
Last active September 14, 2023 04:38
A vscode profile for painless EECS 281 setup.
{"name":"eecs281","settings":"{\"settings\":\"{\\n \\\"editor.emptySelectionClipboard\\\": false,\\n \\\"editor.formatOnSave\\\": true,\\n \\\"editor.inlayHints.enabled\\\": \\\"offUnlessPressed\\\",\\n \\\"editor.insertSpaces\\\": true,\\n \\\"files.associations\\\": {\\n \\\".clangd\\\": \\\"yaml\\\",\\n \\\".clang-format\\\": \\\"yaml\\\"\\n },\\n \\\"files.autoSave\\\": \\\"off\\\",\\n \\\"files.insertFinalNewline\\\": true,\\n \\\"lldb.launch.terminal\\\": \\\"integrated\\\",\\n \\\"lldb.dereferencePointers\\\": false,\\n \\\"[cpp]\\\": {\\n \\\"editor.defaultFormatter\\\": \\\"llvm-vs-code-extensions.vscode-clangd\\\",\\n \\\"editor.semanticHighlighting.enabled\\\": true\\n },\\n \\\"[c]\\\": {\\n \\\"editor.defaultFormatter\\\": \\\"llvm-vs-code-extensions.vscode-clangd\\\",\\n \\\"editor.semanticHighlighting.enabled\\\": true\\n }\\n}\\n\"}","tasks":"{\"tasks\":\"{\\n // See https://go.microsoft.com/fwlink/?LinkId=7
@khuldraeseth
khuldraeseth / MetaBF.cpp
Last active December 8, 2020 02:28
A type-level brainfuck interpreter for the GNU C++ compiler
struct Z {};
template <typename N> struct S {};
struct Nil {};
template <typename X, typename Xs> struct Cons {};
template <typename Ls, typename C, typename Rs> struct Tape {};
struct Inc {};
struct Dec {};
@khuldraeseth
khuldraeseth / MetaPrime.cpp
Created November 13, 2020 17:19
A type-level prime checker for the GNU C++ Compiler
/*
This whole thing is a direct translation from Haskell of
https://gist.github.com/khuldraeseth/d82c8fa8946da845a7bbb57f2077122b
*/
struct F {};
struct T {};
struct Z {};
template <typename N> struct S {};
@khuldraeseth
khuldraeseth / MetaPrime.hs
Created June 21, 2020 14:27
A compile-time prime checker for the Glorious Glasgow Haskell Compilation System
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE UndecidableInstances #-}
-- Booleans
data F
data T
-- Nonnegative integers