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 / 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;
}
}
@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 / 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]})#λ]
// Here's the problem I was having:
scala> val unapply = implicitly[Unapply[Applicative, List[Int]]]
unapply: scalaz.Unapply[scalaz.Applicative,List[Int]] = scalaz.Unapply$$anon$14@5a977cac
scala> implicitly[Unapply[Applicative, unapply.M[unapply.A]]]
<console>:15: error: Unable to unapply type `unapply.M[unapply.A]` 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, unapply.M[unapply.A]])
@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]])
$ 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 / 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))))))
@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;