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 Stream<'T> // abstract type | |
module Stream = | |
// general combinators | |
val map : (Expr<'A> -> Expr<'B>) -> Stream<'A> -> Stream<'B> | |
val collect : (Expr<'A> -> Stream<'B>) -> Stream<'A> -> Stream<'B> | |
val filter : (Expr<'A> -> Expr<bool>) -> Stream<'A> -> Stream<'A> | |
val take : Expr<int> -> Stream<'A> -> Stream<'A> | |
val zipWith : (Expr<'A> -> Expr<'B> -> Expr<'C>) -> Stream<'A> -> Stream<'B> -> Stream<'C> | |
// ... |
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.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html | |
// http://scala-lms.github.io/tutorials/regex.html | |
#r "../packages/FSharp.Compiler.Service.1.3.1.0/lib/net45/FSharp.Compiler.Service.dll" | |
#r "../packages/QuotationCompiler.0.0.7-alpha/lib/net45/QuotationCompiler.dll" | |
open QuotationCompiler |
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 Microsoft.FSharp.Quotations | |
// <@ fun x -> (% <@ x @> ) @> ~ lambda (fun x -> x) | |
let lambda (f : Expr<'T> -> Expr<'R>) : Expr<'T -> 'R> = | |
let var = new Var("__temp__", typeof<'T>) | |
Expr.Cast<_>(Expr.Lambda(var, f (Expr.Cast<_>(Expr.Var var)))) | |
// Staged fixed-point combinator |
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://lambda-the-ultimate.org/node/4039#comment-61431 | |
open Microsoft.FSharp.Quotations | |
// <@ fun x -> (% <@ x @> ) @> ~ lambda (fun x -> x) | |
let lambda (f : Expr<'T> -> Expr<'R>) : Expr<'T -> 'R> = | |
let var = new Var("__temp__", typeof<'T>) | |
Expr.Cast<_>(Expr.Lambda(var, f (Expr.Cast<_>(Expr.Var var)))) | |
// Staged fixed-point combinator |
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 Bool = interface end | |
and True = True with | |
static member inline (|*|) (f, True) = (BoolFold ? (f) <- True) | |
interface Bool | |
and False = False with | |
static member inline (|*|) (f, False) = (BoolFold ? (f) <- False) | |
interface Bool | |
and And<'a, 'b when 'a :> Bool and 'b :> Bool> = And of 'a * 'b with | |
static member inline (|*|) (f, x) = (BoolFold ? (f) <- x) | |
interface Bool |
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
let partition : CloudFlow<'T> -> ('T -> bool) -> (CloudFlow<'T> * CloudFlow<'T>) = fun flow f -> | |
(flow |> CloudFlow.filter f), (flow |> CloudFlow.filter (fun x -> not (f 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
open Microsoft.FSharp.Quotations | |
// <@ fun x -> (% <@ x @> ) @> ~ lambda (fun x -> x) | |
let lambda (f : Expr<'T> -> Expr<'R>) : Expr<'T -> 'R> = | |
let var = new Var("__temp__", typeof<'T>) | |
Expr.Cast<_>(Expr.Lambda(var, f (Expr.Cast<_>(Expr.Var var)))) | |
// fixed-point combinator | |
let rec fix : (('Τ -> 'R) -> ('Τ -> 'R)) -> 'Τ -> 'R = fun f 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
open Microsoft.FSharp.Quotations | |
// <@ fun x -> (% <@ x @> ) @> ~ lambda (fun x -> x) | |
let lambda (f : Expr<'T> -> Expr<'R>) : Expr<'T -> 'R> = | |
let var = new Var("__temp__", typeof<'T>) | |
Expr.Cast<_>(Expr.Lambda(var, f (Expr.Cast<_>(Expr.Var var)))) | |
// encoding of rank-2 polymorphism |
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
let force (value : Lazy<_>) = value.Force() | |
let fix : (Lazy<'T> -> 'T) -> Lazy<'T> = fun f -> | |
let rec x = lazy (f x) in x | |
// Maybe MonadFix | |
let mfix : (Lazy<'T> -> option<Lazy<'T>>) -> Lazy<option<Lazy<'T>>> = fun f -> | |
let rec x = lazy ( match force x with | Some v -> f v | None -> None ) in 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
open MBrace.Core | |
f : Cloud<Int> | |
g,h : int -> Cloud<Int> | |
j,k : int -> int -> Cloud<int> | |
let spawn c = Cloud.StartAsTask c | |
let get t = Cloud.AwaitTask t | |
let (>>=) c f = cloud.Bind(c, f) |