Skip to content

Instantly share code, notes, and snippets.

View pelotom's full-sized avatar

Tom Crockett pelotom

  • Los Angeles, CA
View GitHub Profile
@pelotom
pelotom / multDistOverPlus.idr
Created September 15, 2014 00:43
Multiplication distributes over addition
-- Informal proof:
--==============================================================
-- S a * (b + c)
--= b + c + a * (b + c) -- definition of *
--= b + c + (a * b) + (a * c) -- induction hypothesis
--= b + (a * b) + c + (a * c) -- associativity / commutativity
--= S a * b + S a * c -- definition of *
-- With all associativity and commutativity manipulations:
--==============================================================
@pelotom
pelotom / DecideParity.idr
Last active August 29, 2015 14:07
Idris code for the problem posed in Joseph Abrahamson's type theory talk http://jspha.com/posts/papers_we_love_BOS_2/
-- Axioms
rec_N :
(P : Nat -> Type) ->
(ind : (n : Nat) -> P n -> P (S n)) ->
(base : P Z) ->
(m : Nat) ->
P m
Even : (n : Nat) -> Type
Odd : (n : Nat) -> Type
zeroIsEven : Even Z
@pelotom
pelotom / curry.idr
Last active August 29, 2015 14:09
A dependent curry and uncurry.
curry : {A : Type}
-> {B : A -> Type}
-> {C : Sigma A B -> Type}
-> ((p : Sigma A B) -> C p)
-> (x : A) -> (y : B x) -> C (x ** y)
curry f x y = f (x ** y)
-- Dependent uncurry is just the induction principle for sigma types
uncurry : {A : Type}
-> {B : A -> Type}
@pelotom
pelotom / JavaGenTest.java
Created October 27, 2012 19:17
Muahahaha
public class JavaGenTest {
public static interface F<a, b> {
b f(a a);
}
public static abstract class P2<a, b> {
private static final class _P2<a, b> extends P2<a, b> {
private final a _1;
private final b _2;
@pelotom
pelotom / ABList.hs
Last active December 14, 2015 17:29
data ABList a b = Cons a (ABList b a) | Nil
deriving Show
zipAB :: [a] -> [b] -> ABList a b
zipAB [] _ = Nil
zipAB (a:as) bs = Cons a (zipAB bs as)
-- > zipAB [1..] "hey"
-- Cons 1 (Cons 'h' (Cons 2 (Cons 'e' (Cons 3 (Cons 'y' (Cons 4 Nil))))))
$ git push heroku master
Counting objects: 46, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (40/40), done.
Writing objects: 100% (46/46), 53.45 KiB, done.
Total 46 (delta 0), reused 0 (delta 0)
-----> Fetching custom git buildpack... done
-----> Haskell app detected
-----> Downloading GHC
@pelotom
pelotom / traverseU vs traverseS
Created April 27, 2013 00:21
Why doesn't traverseU work with State? Why must traverseS exist as a special case?
scala> import scalaz._, Scalaz._, Unapply._
import scalaz._
import Scalaz._
import Unapply._
scala> List(1, 2, 3).traverseU((i: Int) => i.pure[({type f[a] = State[Int, a]})#f])
<console>:17: error: Unable to unapply type `scalaz.IndexedStateT[[+X]X,Int,Int,Int]` into a type constructor of kind `M[_]` that is classified by the type class `scalaz.Applicative`
1) Check that the type class is defined by compiling `implicitly[scalaz.Applicative[<type constructor>]]`.
2) Review the implicits in object Unapply, which only cover common type 'shapes'
(implicit not found: scalaz.Unapply[scalaz.Applicative, scalaz.IndexedStateT[[+X]X,Int,Int,Int]])
@pelotom
pelotom / effecfulFibST.scala
Last active December 16, 2015 18:00
Calculating the first n Fibonacci numbers using Effectful with the ST monad.
import effectful._
import scalaz._
import Scalaz._
import effect._
import ST._
import std.indexedSeq._
def fibST(n: Int): List[Int] = {
type ForallST[A] = Forall[({type λ[S] = ST[S, A]})#λ]
@pelotom
pelotom / Brouwer-communication
Last active December 20, 2015 07:38
Excerpts from van Stigt's "Brouwer's Intuitionist Programme"
Brouwer's philosophy of language starts from the conviction that direct
communication between human brings is impossible. His chapter on "Language"
in "Life, Art and Mysticism" starts as follows: "From Life in the Mind
follows the impossibility of communicating directly with others... Never
has anyone been able to communicate directly with others soul-to-soul."
The privacy of mind and thought and and the hypothetical existence of minds
in other human beings, who are no more than the Subject's mind-creations,
"things in the exterior world of the Subject" rule out "any exchange of
thought".
@pelotom
pelotom / gist:8271550
Created January 5, 2014 17:55
Encoding of an algebraic list type in Java
public static abstract class List<a> {
private static final class $Nil<a> extends List<a> {
private $Nil() {
}
public <M> M match(final M $ifNil, final $F<a, $F<List<a>, M>> $ifCons) {
return $ifNil;
}
}