Skip to content

Instantly share code, notes, and snippets.

View joshburgess's full-sized avatar
💭
🤔

Josh Burgess joshburgess

💭
🤔
View GitHub Profile
@joshburgess
joshburgess / EIO.hs
Created February 8, 2019 21:36 — forked from gelisam/EIO.hs
Keeping track of which exceptions have and haven't been handled
-- a continuation of https://gist.github.com/gelisam/137effb33d2777328d366dcb563d8d13
{-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, LambdaCase, MultiParamTypeClasses #-}
module EIO where
import Control.Monad
import Data.Void
import Test.DocTest
import qualified Control.Exception as E
@joshburgess
joshburgess / HKT.swift
Created January 27, 2019 19:49 — forked from anandabits/HKT.swift
Emulating HKT in Swift
// This example shows how higher-kinded types can be emulated in Swift today.
// It acheives correct typing at the cost of some boilerplate, manual lifting and an existential representation.
// The technique below was directly inspired by the paper Lightweight Higher-Kinded Polymorphism
// by Jeremy Yallop and Leo White found at http://ocamllabs.io/higher/lightweight-higher-kinded-polymorphism.pdf
/// `ConstructorTag` represents a type constructor.
/// `Argument` represents an argument to the type constructor.
struct Apply<ConstructorTag, Argument> {
/// An existential containing a value of `Constructor<Argument>`
/// Where `Constructor` is the type constructor represented by `ConstructorTag`
@joshburgess
joshburgess / electric_wadleroo.rs
Created January 23, 2019 02:35 — forked from bodil/electric_wadleroo.rs
Who needs higher kinded types anyway
trait Higher<A, B> {
type Target;
}
trait Higher3<A, B, C> {
type Target2;
type Target3;
}
impl<A, B> Higher<A, B> for Option<A> {
@joshburgess
joshburgess / main.md
Created January 22, 2019 19:18 — forked from hediet/main.md
Proof that TypeScript's Type System is Turing Complete
type StringBool = "true"|"false";


interface AnyNumber { prev?: any, isZero: StringBool };
interface PositiveNumber { prev: any, isZero: "false" };

type IsZero<TNumber extends AnyNumber> = TNumber["isZero"];
type Next<TNumber extends AnyNumber> = { prev: TNumber, isZero: "false" };
type Prev<TNumber extends PositiveNumber> = TNumber["prev"];
@joshburgess
joshburgess / Main.hs
Created January 14, 2019 02:49 — forked from gelisam/Main.hs
Union types (with explicit upcast) in Haskell
-- Example usage
module Main where
import Union
unionValue1 :: Union (String, (Double, ((Int, Int), ())))
unionValue1 = mkUnion "Foo"
unionValue2 :: Union (String, (Double, ((Int, Int), ())))
@joshburgess
joshburgess / Main.hs
Created December 4, 2018 04:41 — forked from gelisam/Main.hs
IndexedMonad example
-- in reply to http://www.reddit.com/r/haskell/comments/21mja6/make_lllegal_state_transitions_unrepresentable/
--
-- We implement a tiny language with three commands: Open, Close, and Get.
-- The first Get after an Open returns 1, the second Get returns 2, and so on.
--
-- Get is only valid while the state is open, and
-- Open must always be matched by a Close.
-- We enforce both restrictions via the type system.
--
-- There are two valid states: Opened and Closed.
@joshburgess
joshburgess / fp-ts-to-the-max-I.ts
Created December 3, 2018 02:07 — forked from gcanti/fp-ts-to-the-max-I.ts
TypeScript port of the first half of John De Goes "FP to the max" (https://www.youtube.com/watch?v=sxudIMiOo68)
import { log } from 'fp-ts/lib/Console'
import { none, Option, some } from 'fp-ts/lib/Option'
import { randomInt } from 'fp-ts/lib/Random'
import { fromIO, Task, task } from 'fp-ts/lib/Task'
import { createInterface } from 'readline'
//
// helpers
//
@joshburgess
joshburgess / foo.ts
Created November 30, 2018 07:32 — forked from OliverJAsh/foo.ts
React Redux: infer Redux props from mappers
import React, { SFC } from 'react';
import { MapDispatchToPropsParam, MapStateToPropsParam } from 'react-redux';
import { StateRoot } from 'reducers/types';
import { AnyAction, Dispatch } from 'redux';
//
// Helpers
//
const createSubType = <T extends any>() => <SubType extends T>(subType: SubType) => subType;
@joshburgess
joshburgess / fp-ts-to-the-max-II.ts
Created November 27, 2018 16:34 — forked from gcanti/fp-ts-to-the-max-II.ts
TypeScript port of the second half of John De Goes "FP to the max" (https://www.youtube.com/watch?v=sxudIMiOo68)
import { log } from 'fp-ts/lib/Console'
import { Type, URIS } from 'fp-ts/lib/HKT'
import { none, Option, some } from 'fp-ts/lib/Option'
import { randomInt } from 'fp-ts/lib/Random'
import { fromIO, Task, task, URI as TaskURI } from 'fp-ts/lib/Task'
import { createInterface } from 'readline'
//
// helpers
//
@joshburgess
joshburgess / gstash.sh
Created November 7, 2018 08:20 — forked from junegunn/gstash.sh
gstash
gstash() {
local out k reflog
out=(
$(git stash list --pretty='%C(yellow)%gd %>(14)%Cgreen%cr %C(blue)%gs' |
fzf --ansi --no-sort --header='enter:show, ctrl-d:diff, ctrl-o:pop, ctrl-y:apply, ctrl-x:drop' \
--preview='git stash show --color=always -p $(cut -d" " -f1 <<< {}) | head -'$LINES \
--preview-window=down:50% --reverse \
--bind='enter:execute(git stash show --color=always -p $(cut -d" " -f1 <<< {}) | less -r > /dev/tty)' \
--bind='ctrl-d:execute(git diff --color=always $(cut -d" " -f1 <<< {}) | less -r > /dev/tty)' \
--expect=ctrl-o,ctrl-y,ctrl-x))