Skip to content

Instantly share code, notes, and snippets.

/*
struct G<A> {
let vertices : [A]
let edges: [(A, A)]
}
let gex = G(vertices: [1, 2, 3], edges: [(1, 2), (2, 3)])
let gbad = G(vertices: [1], edges: [(1, 2)])
*/
module MonadsAsModules where
import Agda.Primitive using (Level)
id : ∀ {k}{X : Set k} → X → X
id x = x
const : ∀ {a b} {A : Set a} {B : Set b} → A → B → A
const x _ = x
@CodaFi
CodaFi / update-swift-dev
Last active February 13, 2018 15:46 — forked from ddunbar/update-swift-dev
This is the script I currently use on OS X to get a working "swift-dev.xctoolchain" out of a built Swift. It isn't designed to work for anyone but me, but it should be easy to adapt. I always run this after every build, and then use `TOOLCHAINS=swift-dev swift build` (etc) to use the development compiler.
#!/bin/sh
set -e
if [ -z "${SWIFTPM_CONFIGURATION}" ]; then
SWIFTPM_CONFIGURATION=.bootstrap/lib/swift/pm/4
fi
if [ -z "${CONFIGURATION}" ]; then
CONFIGURATION=release
// swift -Xfrontend -debug-constraints
infix operator ^&&^ : LogicalConjunctionPrecedence
infix operator ^||^ : LogicalConjunctionPrecedence
struct T{}
struct F{}
func λ(_ f : (T) -> ()) {
print("true")
@CodaFi
CodaFi / Subtyping.swift
Created March 31, 2017 20:40
"Efficient Subtyping" (if you ignore all the inefficiencies).
indirect enum Type : CustomStringConvertible {
case TyVar(String)
case Top
case Bottom
case Arrow(Type, Type)
case Pair(Type, Type)
case Rec(String, Type)
func subst(_ s : String, _ t : Type) -> Type {
switch self {

Explicit Toll-Free Conversions

Introduction

To continue removing further implicit conversions from the language, implicit toll-free bridging should be deprecated in Swift 3 and removed in Swift 4.0.

@CodaFi
CodaFi / Fmt.swift
Last active March 23, 2017 15:47
Typesafe format strings following Danvy, 1998
/// Playground - noun: a place where people can play
/// An un-parser for things is a continuation on strings...
precedencegroup CompositionPrecedence {
associativity: right
higherThan: BitwiseShiftPrecedence
}
prefix operator <<
postfix operator >>
indirect enum Type : CustomStringConvertible {
case nat
case product(Type, Type)
case arrow(Type, Type)
var description : String {
switch self {
case .nat:
return "ℕ"
case let .product(t1, t2):
@CodaFi
CodaFi / Channel.swift
Created February 27, 2017 22:45
[WIP] Session Types as good as I could get em. Ported from the Rust implementation by Philip Munksgaard.
//
// Channel.swift
// Sessions
//
// Created by Robert Widmann on 2/27/17.
// Copyright © 2017 TypeLift. All rights reserved.
//
enum FakeError : Error {
case Error
@CodaFi
CodaFi / Proposal.md
Last active October 12, 2023 00:03