Skip to content

Instantly share code, notes, and snippets.

View brendanzab's full-sized avatar
😵‍💫
writing elaborators

Brendan Zabarauskas brendanzab

😵‍💫
writing elaborators
View GitHub Profile
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
typedef int i; //Save space by using 'i' instead of 'int'
typedef float f; //Save even more space by using 'f' instead of 'float'
//Define a vector class with constructor and operator: 'v'
struct v {
f x,y,z; // Vector has three float attributes.
@cnd
cnd / gist:7098985
Last active December 26, 2015 05:09
use std::task;
use std::rt::io::timer::sleep;
///<Summary>
///Simple butterfly
///</Summary>
pub fn butterfly<U>(f: &fn() -> U) -> U {
let (port, chan) = stream();
do task::spawn_sched(task::SingleThreaded) {
print(" ");
@gelisam
gelisam / IdiomaticLens.hs
Last active September 7, 2017 13:07
Idiomatic Lens
-- in reply to http://www.reddit.com/r/haskell/comments/23uzpg/lens_is_unidiomatic_haskell/
--
-- What the lens library might look like if Getter, Setter, Fold, Traversal,
-- Lens, Review, and Prism were separate datatypes.
--
-- For each optic, I only define enough combinators to explore pairs/sums
-- and lists of integers. Whenever possible, I reimplement the same
-- combinators and the same examples with all optics.
module IdiomaticLens where
@rntz
rntz / tonetheory.ml
Last active March 4, 2018 20:24
An introduction to tone theory, and subtyping for a fragment of modal Datafun
(* A quick note about preorders; skip this if you know about them.
*
* A preorder is a relation (a ≤ b) satisfying two rules:
* 1. Reflexivity: a ≤ a.
* 2. Transitivity: if a ≤ b and b ≤ c then a ≤ c.
*
* A good example of a preorder is "lists under containment":
* let (X ≤ Y) if every element of the list X is also in Y.
*
* Preorders are like partial orders, but without requiring antisymmetry.
@ichistmeinname
ichistmeinname / leftpad.v
Created April 23, 2018 20:48
Proofs about leftpad inspired by ezrakilty -- https://github.com/ezrakilty/hillel-challenge
Require Import Lists.List.
Require Import Arith.Arith.
Require Import Omega.
Set Implicit Arguments.
Fixpoint replicate A (n : nat) (x : A) : list A :=
match n with
| O => nil
@UlfNorell
UlfNorell / Fulcrum.agda
Created April 27, 2018 11:04
Challenge 3 of the Great Theorem Prover Showdown
-- Problem 3 of @Hillelogram's Great Theorem Prover Showdown.
-- https://www.hillelwayne.com/post/theorem-prover-showdown
--
-- Implemented using current stable-2.5 branch of Agda
-- (https://github.com/agda/agda/tree/08664ac) and the agda-prelude
-- library (https://github.com/UlfNorell/agda-prelude/tree/d193a94).
module Fulcrum where
open import Prelude hiding (_≤?_)
@sjoerdvisscher
sjoerdvisscher / laws.hs
Last active July 24, 2018 08:16
First class checkable laws using the free-functors package
{-# LANGUAGE
TypeFamilies
, KindSignatures
, ScopedTypeVariables
, ConstraintKinds
, FlexibleInstances
, FlexibleContexts
, DeriveGeneric
, DeriveAnyClass
, TypeApplications

What I did to install Coq 8.8.1 with equations 1.1 as a separate profile:

opam switch coq-8.8.1 --alias-of 4.06.1
eval `opam config env`
opam pin add coq 8.8.1
opam pin add coq-equations 1.1+8.8
opam install ott coq-ott
(opam pin -y add coq-equations 1.1+8.8 && opam install -y ott coq-ott)

I lack notes, but you can repeat opam switch profileName --alias-of 4.06.1 more times

@rntz
rntz / bidir-nbe.rkt
Last active October 7, 2018 14:21
Bidirectional typechecking and normalisation by evaluation for a simply-typed lambda calculus, all in one
;; Based on http://homepages.inf.ed.ac.uk/slindley/nbe/nbe-cambridge2016.pdf
#lang racket
;; Checks that a term has a type and returns its denotation.
(define (check cx tp-expect term)
(match term
[`(lambda (,x) ,body)
(match-define `(-> ,A ,B) tp-expect)
(define thunk (check (hash-set cx x A) B body))
(lambda (env) (lambda (v) (thunk (hash-set env x v))))]
@rntz
rntz / bidir-nbe.ml
Last active October 7, 2018 14:25
Bidirectional typechecking and normalisation by evaluation for a simply-typed lambda calculus, all in one
(* Based on http://homepages.inf.ed.ac.uk/slindley/nbe/nbe-cambridge2016.pdf *)
exception TypeError
type tp = Base | Fn of tp * tp
let subtype (x: tp) (y: tp): bool = x = y
type sym = {name: string; id: int}
let next_id = ref 0
let nextId() = let x = !next_id in next_id := x + 1; x