Skip to content

Instantly share code, notes, and snippets.

View Mzk-Levi's full-sized avatar

Melchizedek Mzk-Levi

View GitHub Profile
package scalaz
import scalaz.{State => _, _}
import scalaz.Free.FreeC
import scalaz.Id.Id
import FreeState.StateF
sealed abstract class FreeState[S, A] {
def map[B](f: A => B): FreeState[S, B]
}
@tonymorris
tonymorris / Terminal.hs
Created May 22, 2014 09:04
Terminal I/O with Free
{-# LANGUAGE RankNTypes #-}
data Free f a =
Done a
| More (f (Free f a))
instance Functor f => Functor (Free f) where
fmap f (Done a) =
Done (f a)
fmap f (More k) =
@runarorama
runarorama / gist:9422453
Last active August 29, 2015 13:57
Suggestion for the new representation of `IO` in Scalaz.
import scalaz._
import \/._
import Free._
import scalaz.syntax.monad._
import java.util.concurrent.atomic.AtomicReference
import java.util.concurrent.CountDownLatch
object Experiment {
sealed trait OI[A] {
def map[B](f: A => B): OI[B]
object Trampolines {
def odd[A](as: List[A]): TailRec[Boolean] =
as match {
case Nil => Return(false)
case _ :: xs => Suspend(() => even(xs))
}
def even[A](as: List[A]) = as match {
case Nil => Return(true)
case _ :: xs => Suspend(() => odd(xs))
@nvanderw
nvanderw / Free.ml
Created February 14, 2014 04:48
Free monads in OCaml, for great referential transparency
module type Functor = sig
type 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
end
module type Monad = sig
type 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
val return : 'a -> 'a t

Reasoning

  • observations lead to conclusions
  • conclusions, based on observations, lead to new conclusions
  • conclusions do not lead to themselves
  • conclusions do not lead to observations

You might suspect something to be true (a conclusion). You question why you believe it to be true -- hypothesis formation. When you fail to find reasons to believe it to be true, you abandon the hypothesis. It could be that:

package com.nicta
package jdbc
import java.sql.SQLException
import scalaz._, Scalaz._
// 1 + A
sealed trait ?[A] {
import ?._

JDBC API for Scala

Data types required

Primitives

  • Option[A] (?)
  • SQLException / A (/)
  • InvariantNotMet / A (~)
  • SqlEffect[A] (!)
@pthariensflame
pthariensflame / Lens.agda
Last active December 30, 2015 17:39
Residual representations of `Lens` and `PLens` in Agda, and the canonical embedding of the former into the latter.
module Lens where
open import Level
open import Function
open import Relation.Binary
open import Data.Product
open import Relation.Binary.Product.Pointwise
open import Data.Sum
open import Relation.Binary.Sum
open import Data.Empty
open import Function.Inverse