Skip to content

Instantly share code, notes, and snippets.

View tonymorris's full-sized avatar

Tony Morris tonymorris

View GitHub Profile
import Data.Text
import Control.Monad.Reader
data ZResult a =
ZVal a
| ZNotFound
| ZFail Text
| ZUnauth Text
newtype ZResultT m a = ZResultT {
import Data.Text
import Control.Monad.Reader
data ZResult a =
ZVal a
| ZNotFound
| ZFail Text
| ZUnauth Text
newtype ZResultT m a = ZResultT {
import Data.Text
import Control.Monad.Reader
data ZResult a =
ZVal a
| ZNotFound
| ZFail Text
| ZUnauth Text
instance Functor ZResult where
import Data.Monoid
import Control.Monad.State
import Control.Monad.Reader
data RequestHeaders =
RequestHeaders [(String, String)]
data ResponseHeaders =
ResponseHeaders [(String, String)]
// taken from http://hackage.haskell.org/package/contstuff
trait Functor[F[+_]] {
def fmap[A, B](f: A => B): F[A] => F[B]
}
trait Apply[F[+_]] extends Functor[F] {
def ap[A, B](f: F[A => B]): F[A] => F[B]
}
@tonymorris
tonymorris / SKI_Applicative.scala
Created August 2, 2012 04:59
Applicative Functor / SKI combinator calculus
object SKI_Applicative {
/*
First, let's talk about the SK combinator calculus and how it contributes to solving your problem.
The SK combinator calculus is made of two functions (aka combinators): S and K. It is sometimes called the SKI combinator calculus, however, the I combinator can be derived from S and K. The key observation of SK is that it is a turing-complete system and therefore, anything that can be expressed as SK is also turing-complete. Here is a demonstration that Scala's type system is turing-complete (and therefore, undecidable) for example[1].
The K combinator is the most trivial of the two. It is sometimes called "const" (as in Haskell). There is also some discussion about its evaluation strategy in Scala and how to best express it[2]. The K function might be paraphrased as, "takes a value and returns a (constant) unary function that always returns that value."
*/
def k[A, B]: A => B => A =
a => _ => a
using System;
class Test {
Func<int, int> Hi() {
return a => {
var i = 7;
return a + i + 10;
};
}
}
[Event "Edited position"]
[Site ""]
[Date "2012.01.25"]
[Round "-"]
[White "-"]
[Black "-"]
[Result "*"]
[FEN "5Kbk/6pp/6P1/8/8/8/8/7R w - - 0 1"]
[SetUp "1"]
@tonymorris
tonymorris / Lens.cs
Created August 5, 2012 05:43
Lens library for C# (demonstration)
using System;
using System.Collections;
using System.Collections.Generic;
/*
A basic lens library for the purpose of demonstration.
Implements a lens as the costate comonad coalgebra.
This library is not complete.
A more complete lens library would take from
$ cat ~/.xchat2/xchatlogs/FreeNode-#scala.log | grep szeiger | grep joined # UTC+10
Apr 25 18:42:48 * szeiger (~szeiger@2002:80b3:432b:0:b1b7:baed:df9e:f0bf) has joined #scala
Apr 25 18:52:02 * szeiger_ (~szeiger@scala1.epfl.ch) has joined #scala
Apr 26 02:28:11 * szeiger (~szeiger@134-13.194-178.cust.bluewin.ch) has joined #scala
May 12 20:14:25 * szeiger (~szeiger@217-64.62-188.cust.bluewin.ch) has joined #scala
May 13 20:02:03 * szeiger (~szeiger@217-64.62-188.cust.bluewin.ch) has joined #scala
May 14 00:33:08 * szeiger (~szeiger@217-64.62-188.cust.bluewin.ch) has joined #scala
May 14 17:17:43 * szeiger (~szeiger@psepc1.epfl.ch) has joined #scala
May 14 18:51:59 * szeiger (~szeiger@psepc1.epfl.ch) has joined #scala
May 14 18:59:28 * szeiger_ (~szeiger@psepc1.epfl.ch) has joined #scala