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.madore.org/~david/programs/unlambda/ | |
type C = F -> unit | |
and F = F of ((F * C) -> unit) | |
let getReader (source : string) = | |
let pos = ref 0 | |
(fun () -> let result = source.[!pos] in pos := !pos + 1; result) | |
let eval (source : string) = |
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 TrampValue<'T> = | |
| DelayValue of Delay<'T> | |
| ReturnValue of Return<'T> | |
| BindValue of IBind<'T> | |
and ITramp<'T> = | |
abstract member Value : TrampValue<'T> | |
abstract member Run : unit -> 'T | |
and Delay<'T>(f : unit -> ITramp<'T>) = | |
member self.Func = 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
open System | |
[<AutoOpen>] | |
module AsyncEx = | |
type private SuccessException<'T>(value : 'T) = | |
inherit Exception() | |
member self.Value = value | |
type Microsoft.FSharp.Control.Async with | |
// efficient raise |
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 { |
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 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
#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
// 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
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://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 |