Skip to content

Instantly share code, notes, and snippets.

View Kazark's full-sized avatar

Keith Pinson Kazark

  • Undisclosed
View GitHub Profile
@Kazark
Kazark / Guard.idr
Last active October 25, 2019 01:02
Who needs constructivism? Make types out of Boolean predicates! (Encoded constructively...)
module Guard
%default total
%access public export
data Guarded : (a -> Bool) -> a -> Type where
Guard : (pred : a -> Bool) -> (subject : a) -> (prf : pred subject = True)
-> Guarded pred subject
data GuardedIsBogus : Type where
@Kazark
Kazark / AndOr.idr
Last active July 12, 2019 13:51
Sigma+Nat suffice for ADTs
module AndOr
%default total
%access private
TData : Type -> Type -> Nat -> Type
TData a _ Z = a
TData a b (S Z) = (a, b)
TData _ b (S (S Z)) = b
TData _ _ _ = Void
@Kazark
Kazark / .bashrc
Created December 12, 2019 16:37
Bash Post Git PROMPT_COMMAND
export PROMPT_COMMAND="__posh_git_ps1 '${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;34m\] \w' '\[\033[34m\]\$\[\033[00m\] '"
@Kazark
Kazark / main.c
Created April 16, 2020 01:32
Usable Lisp-style symbols, without a global symbol table or interning or heavyweight strings
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct MaybeULong {
const unsigned long nothing;
const unsigned long x;
} MaybeULong;
@Kazark
Kazark / Bijection.idr
Last active May 4, 2020 21:13
Basic implementation of correct-by-construction bijections
module Bijection
%default total
%access public export
infixr 5 <=>
record (<=>) a p where
constructor Biject
ap : a -> p
@Kazark
Kazark / CurryHoward.lhs
Last active January 12, 2024 13:21
Curry-Howard Tutorial in Literate Haskell
This is a tutorial on the Curry-Howard correspondence, or the correspondence
between logic and type theory, written by Keith Pinson, who is still a learner
on this subject. If you find an error, please let me know.
This is a Bird-style literate Haskell file. Everything is a comment by default.
Lines of actual code start with `>`. I recommend that you view it in an editor
that understands such things (e.g. Emacs with `haskell-mode`). References will
also be made to Scala, for programmers less familiar with Haskell.
We will need to turn on some language extensions. This is not an essay on good
@Kazark
Kazark / sqrt.scm
Created July 2, 2020 22:20
A playful implementation of square root in Guile, with a Haskell flavor
#| An obfuscated Haskell-style solution to exercise 1.7 from SICP in Guile.
|
| The basis of this solution is the idea: the numerical method for square root
| does not inherently have any notion of what is means for the solution to be
| "good enough"; that is an _orthogonal_ concern. The inherent idea, in its
| purest form, is a limit of the algorithm considered as a function of the
| number of iterations. Therefore, it would be pleasing in our implementation
| to divorce the idea of what "good enough" means from our expression of the
| algorithm. But this requires an infinite data structure, because if we do not
| have an infinite data structure, we must from the first think about when to
@Kazark
Kazark / Example.scala
Created August 5, 2020 19:09
Cats .widen (covariant functors) and .narrow (contravariant functors): both are for upcasts, and thus safe
package example
import cats._
import cats.implicits._
sealed trait List[+A]
case object Nil extends List[Nothing]
final case class Cons[A](head: A, tail: List[A]) extends List[A]
final case class Co[I, A](run : I => A)
@Kazark
Kazark / FunctionalAbstractions.lhs
Created August 7, 2020 15:00
Exercises to familiarize yourself with many standard typeclasses
We are going to be redefining a bunch of things that are in prelude in order to
make them explicit and all in one place:
> {-# LANGUAGE NoImplicitPrelude #-}
It is best for learning to be able to write concretized signatures of typeclass
functions when defining instances:
> {-# LANGUAGE InstanceSigs #-}
@Kazark
Kazark / Two.agda
Last active August 21, 2020 21:57
Lawfulness of applicative implementations than compile for homogenous pair
module Two where
open import Level using (Level)
open import Function using (_∘_; id; _$_)
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎; step-≡; step-≡˘)
data Two (A : Set) : Set where
TwoOf : A → A → Two A