This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://homepages.inf.ed.ac.uk/slindley/papers/handlers-draft-march2013.pdf | |
// Quote from the paper | |
// Effect handler operation clauses generalise exception handler clauses | |
// by adding a continuation argument, providing support for arbitrary effects. An operation | |
// clause is an exception clause if it ignores its continuation argument. | |
type Cont<'T, 'R> = Cont of ((('T -> 'R) * (exn -> 'R)) -> 'R) | |
type ContBuilder() = | |
member self.Return x = Cont (fun (k, _) -> k x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Cont<'T, 'S, 'R> = Cont of (('T -> 'S) -> 'R) | |
type ContBuilder() = | |
member self.Return x = Cont (fun k -> k x) | |
member self.Bind (c : Cont<_, _, _>, f : _ -> Cont<_, _, _>) = | |
Cont (fun k -> let (Cont contf) = c in contf (fun v -> let (Cont contf') = f v in contf' k)) | |
let delim = new ContBuilder() | |
let run (c : Cont<_, _, _>) = let (Cont contf) = c in contf id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.eecs.harvard.edu/~tov/pubs/haskell-session-types/session08.pdf | |
// Basic Operations | |
[<AbstractClass>] | |
type Ops = class end | |
type Eps = class inherit Ops end | |
type Send<'T, 'Rest when 'Rest :> Ops> = class inherit Ops end | |
type Recv<'T, 'Rest when 'Rest :> Ops> = class inherit Ops end | |
type Choose<'Left, 'Right when 'Left :> Ops and 'Right :> Ops> = class inherit Ops end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://clojure.com/blog/2012/05/08/reducers-a-library-and-model-for-collection-processing.html | |
module Reducer = | |
open System | |
open System.Text | |
open System.Collections.Generic | |
type ReduceFunc<'T,'R> = | |
abstract Invoke : 'T * 'R -> 'R |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Peano = interface end | |
and Zero = Zero with | |
static member inline (|*|) (f, Zero) = f $ Zero | |
interface Peano | |
and Succ<'a when 'a :> Peano> = Succ of 'a with | |
static member inline (|*|) (f, Succ(x)) = f $ Succ(x) | |
interface Peano | |
type PeanoToInt = PeanoToInt with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://lampwww.epfl.ch/~odersky/papers/fsttcs2009.pdf | |
open System | |
open System.Text | |
open System.Collections.Generic | |
// Type classes encoding for iteration and building | |
type Iterable<'From, 'Elem> = Iterable of (('Elem -> unit) -> unit) | |
type Iter = Iter with | |
static member inline ($) (_ : Iter, values : 'Elem []) = | |
Iterable (fun f -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#time | |
let rec Y f x = f (Y f) x | |
let Y' f x = | |
let r = ref Unchecked.defaultof<'a -> 'b> | |
r := (fun x -> f !r x) | |
f !r x | |
let iter f x = if x = 100000000 then x else f (x + 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Expr<'T> = | |
abstract Eval : unit -> 'T | |
let eval (x : Expr<'T>) = x.Eval() | |
let lift (value : 'T) = | |
{ new Expr<'T> with | |
member self.Eval () = value | |
} | |
let tup (first : Expr<'T>) (second : Expr<'S>) = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Church = | |
abstract Apply<'T> : ('T -> 'T) * 'T -> 'T | |
let zero = | |
{ | |
new Church with | |
member self.Apply(f, x) = x | |
} | |
let succ (nat : Church) = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Microsoft.FSharp.Control.Async with | |
static member Raise (e : #exn) = Async.FromContinuations(fun (_,econt,_) -> econt e) | |
#time | |
for i in [|1..1000000|] do | |
try | |
raise <| new System.Exception() | |
with ex -> () | |
async { |