Skip to content

Instantly share code, notes, and snippets.

View Kazark's full-sized avatar

Keith Pinson Kazark

  • Undisclosed
View GitHub Profile
@Kazark
Kazark / TKD.hs
Created September 15, 2016 19:24
Code from LambdaConf 2015 Type Kwan Do workshop
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE ScopedTypeVariables #-}
module TKD where
import Control.Applicative
befunge :: (x -> y) -> (y -> (w, z)) -> x -> w
befunge f g =
fst . g . f
@Kazark
Kazark / wdiff.vim
Created July 8, 2017 12:56 — forked from ynkdir/wdiff.vim
wdiff.vim
" Usage:
" Copy this file to your ~/.vim/autoload directory.
" :edit oldfile
" :new newfile
" :call wdiff#highlight(2, 1) " wdiff#highlight(winnr1, winnr2)
let s:save_cpo = &cpo
set cpo&vim
function wdiff#highlight(Awinnr, Bwinnr)
@Kazark
Kazark / NotNotLEM.idr
Last active November 13, 2018 15:17
Intuitionist logic is by no means denying the law of excluded middle!
module NotNotLEM
%default total
%access public export
notDistributesOverEither : Not (Either a b) -> (Not a, Not b)
notDistributesOverEither neither = (notLeft neither, notRight neither) where
notLeft : Not (Either a b) -> Not a
notLeft neither x = neither (Left x)
@Kazark
Kazark / Rubik.idr
Last active December 28, 2018 03:01
Considering only one face of a Rubik's cube: reduce a set of turns to an orientation
module Rubik
%default total
%access public export
||| "North", "south", "east" and "west" face orientations
data Orient = N | E | S | W
turnCW : Orient -> Orient
turnCW N = E
@Kazark
Kazark / ExhaustivePrint.idr
Created January 12, 2019 21:15
How to create exhaustive print function for "enum" in Idris, off a string map
%default total
data RPS = Rock | Paper | Scissors
Eq RPS where
Rock == Rock = True
Paper == Paper = True
Scissors == Scissors = True
_ == _ = False
@Kazark
Kazark / GADT.fsx
Last active February 14, 2019 20:12
Generalized Algebra Data Types for DSLs, with Free Monads, in F#
/// Example encoding of the shape of GADT one finds for request types
module Request =
/// The constructors must be kept private, so that we can refine the types of
/// the introduction rules.
type T<'a> =
private
| FileExists' of string
| ReadText' of string
| GetCwd'
@Kazark
Kazark / Maybe.cs
Last active October 25, 2019 01:05
Maybe monad encoding in C#
class Nothing : Exception {}
public static class Maybe {
public static void Nothing() => throw new Nothing();
public static void Guard(bool cond) { if (!cond) Nothing(); }
public static void GuardNot(bool cond) { if (cond) Nothing(); }
}
public static class TryParse {
public static UInt32 UInt32(string x) {
@Kazark
Kazark / Env.fsx
Created March 6, 2019 21:43
An F# toy example of Scala ZIO Environment
module EnvDemo
open System
open System.IO
[<Struct>]
type Nothing =
private
| Nothing
@Kazark
Kazark / ThisOrThese.agda
Created March 11, 2019 21:48
Like either but applicative instance accumulates lefts
module Data.ThisOrThese where
open import Data.List.Base
open import Data.List.NonEmpty
open import Relation.Binary.PropositionalEquality.Core
open import Function
-- Apparently this is called ValidatedNel in Cats.
data ThisOrThese : Set -> Set -> Set where
These : ∀ {A B} -> List⁺ A -> ThisOrThese A B
@Kazark
Kazark / Id.agda
Created March 14, 2019 15:39
Identity functor and monad laws
module Id where
open import Relation.Binary.PropositionalEquality.Core
open import Function
data Id : Set → Set where
Itself : ∀{A} → A → Id A
fmap : ∀{A B} → (A → B) → Id A → Id B
fmap f (Itself x) = Itself (f x)