This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE InstanceSigs #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
module TKD where | |
import Control.Applicative | |
befunge :: (x -> y) -> (y -> (w, z)) -> x -> w | |
befunge f g = | |
fst . g . f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%default total | |
data RPS = Rock | Paper | Scissors | |
Eq RPS where | |
Rock == Rock = True | |
Paper == Paper = True | |
Scissors == Scissors = True | |
_ == _ = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module EnvDemo | |
open System | |
open System.IO | |
[<Struct>] | |
type Nothing = | |
private | |
| Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |