Skip to content

Instantly share code, notes, and snippets.

View larsrh's full-sized avatar
🏝️
On hiatus.

Lars Hupel larsrh

🏝️
On hiatus.
View GitHub Profile
@larsrh
larsrh / clist.ml
Created November 16, 2012 22:20
GADTs in OCaml
type _ complist =
One : ('a -> 'b) -> ('a * 'b) complist
| Cons : ('a -> 'b) * ('b * 'c) complist -> ('a * 'c) complist
let rec clength : type a . a complist -> int = function
| One _ -> 1
| Cons (_, xs) -> 1 + clength xs
let rec ccompose : type a b . (a * b) complist -> (a -> b) = function
| One f -> f
@larsrh
larsrh / kleislist.ml
Created November 17, 2012 20:12
GADTs in OCaml, part 2
module type Monad = sig
type 'a m
val bind : 'a m -> ('a -> 'b m) -> 'b m
val return: 'a -> 'a m
end
@larsrh
larsrh / main.scala
Created November 24, 2012 11:48
private escaping scope
object Test extends App {
val x = foo.Foo.privateX
println(x)
println(x.foo)
}
@larsrh
larsrh / nat.ml
Created December 2, 2012 23:31
GADTs in OCaml, part 3
open String
module Nat = struct
type nat = Z | S of nat
let rec int_of_nat = function
| Z -> 0
| S n -> 1 + int_of_nat n
@larsrh
larsrh / undot.scala
Created December 16, 2012 10:20
Code example in https://github.com/scalaz/scalaz/pull/224 with complete imports
import scalaz._
import Id.Id
import undo._
import UndoT._
import syntax.show._
import syntax.monoid._
import std.string._
import std.anyVal._
def combine[F[_, _], S, A](f: F[S, A])(implicit F: MonadState[F, S], S: Show[S], A: Show[A]) =
@larsrh
larsrh / rc.conf
Created December 16, 2012 17:16
Main configuration of my Arch system
#
# /etc/rc.conf - Main Configuration for Arch Linux
#
# See 'man 5 rc.conf' for more details
#
DAEMONS=(@sensors)
# Storage
#
@larsrh
larsrh / traverse.scala
Created December 18, 2012 19:12
Small example of `traverse`.
import scalaz._
import Scalaz._
val pf: Int => Option[Int] = PartialFunction.condOpt(_) { case 3 => 30; case 4 => 40 }
scala> List(1, 2, 3, 4).traverse(pf)
res0: Option[List[Int]] = None
scala> List(3, 4).traverse(pf)
res1: Option[List[Int]] = Some(List(30, 40))
@larsrh
larsrh / A.scala
Created January 11, 2013 23:14
package object magic
package std
trait A {
class A(n: Int)
}
object a extends A
@larsrh
larsrh / monoid.scala
Last active December 11, 2015 03:38
Spire bindings for Scalaz? Or are they Scalaz bindings for Spire?
package scalaz.contrib
package spire
import _root_.spire.algebra
trait MonoidOps[F] extends SemigroupOps[F] {
def asSpire: algebra.Monoid[F]
def asScalaz: scalaz.Monoid[F]
@larsrh
larsrh / symbols.md
Created January 20, 2013 22:04
Symbols in scalaz6/scalaz7
8
Symbol scalaz6 scalaz7
>>= 19