Skip to content

Instantly share code, notes, and snippets.

View joshburgess's full-sized avatar
💭
🤔

Josh Burgess joshburgess

💭
🤔
View GitHub Profile
@joshburgess
joshburgess / CheckStrictness.hs
Created November 22, 2022 21:23 — forked from anka-213/CheckStrictness.hs
A type class for statically checking if data is fully strict
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}
module CheckStrictness where
import GHC.Generics
@joshburgess
joshburgess / DKT.hs
Created April 17, 2020 08:50 — forked from paf31/DKT.hs
Statically-typed values with dynamically-kinded types
{-# language FlexibleContexts #-}
{-# language TypeOperators #-}
module DKT where
import Control.Monad (guard)
import Control.Monad.Error.Class (throwError)
import Control.Monad.Trans (lift)
import Control.Monad.Trans.State
import Control.Monad.Trans.Writer
@joshburgess
joshburgess / Commit.hs
Created April 10, 2020 09:04 — forked from i-am-tom/Commit.hs
Apply your function parameters in any order, for no reason other than that you can.
{-# lAnGuAgE DataKinds #-}
{-# LaNgUaGe FlexibleInstances #-}
{-# lAnGuAgE FunctionalDependencies #-}
{-# LaNgUaGe KindSignatures #-}
{-# lAnGuAgE TypeFamilies #-}
{-# LaNgUaGe TypeOperators #-}
{-# lAnGuAgE UndecidableInstances #-}
module Commit where
import Data.Kind (Constraint, Type)
@joshburgess
joshburgess / GADT.ts
Created March 17, 2020 15:20 — forked from gcanti/GADT.ts
Approximating GADTs in TypeScript
// Adapted from http://code.slipthrough.net/2016/08/10/approximating-gadts-in-purescript/
import { Kind, URIS } from 'fp-ts/lib/HKT'
import { URI } from 'fp-ts/lib/Identity'
import { identity } from 'fp-ts/lib/function'
// ------------------------------------------
// Leibniz
// ------------------------------------------

Monads and delimited control are very closely related, so it isn’t too hard to understand them in terms of one another. From a monadic point of view, the big idea is that if you have the computation m >>= f, then f is m’s continuation. It’s the function that is called with m’s result to continue execution after m returns.

If you have a long chain of binds, the continuation is just the composition of all of them. So, for example, if you have

m >>= f >>= g >>= h

then the continuation of m is f >=> g >=> h. Likewise, the continuation of m >>= f is g >=> h.

BuckleScript friendly vim + official ocaml-lsp setup for Reason/OCaml

Prerequisite: Install esy 0.6.0.

Steps

  1. Check esy version (it has to be >0.6.0)
  2. Create esy.json with the following contents next to package.json:
@joshburgess
joshburgess / NamedTuple.hs
Created October 9, 2019 23:21 — forked from PkmX/NamedTuple.hs
Using type-level symbols and overloaded labels to make named tuples
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedLabels #-}
find ~/Work -name stack.yaml | xargs grep -o '^resolver: \([^#]*\)'
@joshburgess
joshburgess / PolymorphicExceptions.re
Last active October 1, 2019 03:50
Weird edge case allowing polymorphic exceptions in ReasonML/OCaml
/* Uncomment below line to see error */
/* exception Absurd('a); */
/* ^^ Error: Unbound type parameter 'a */
/*
Normally, exceptions are monomorphic. They usually cannot take in type params...
*/
/*
...But what if we skip the `exception` syntax sugar and just use the `+=` open
@joshburgess
joshburgess / tc.cpp
Created September 26, 2019 05:44 — forked from carymrobbins/tc.cpp
An example of implementing type classes in C++.
/*
To compile and run -
% g++ tc.cpp -std=c++11 -o tc
% ./tc
2, 4, 6, 8
*/
#include <functional>
#include <iostream>