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 Term<'a>() = class end | |
type Tuples' = Tuples' with | |
static member inline (?<-) (_ : Tuples', _ : (Term<_> * Term<_>), _ : (Term<_> * Term<_>)) = 2 | |
static member inline (?<-) (_ : Tuples', a:Term<_>, b : Term<_>) = 4 | |
static member inline (?<-) (_ : Tuples', a:bool, b:bool) = 3 | |
static member inline (?<-) (_ : Tuples', a:string, b:string) = 1 | |
let inline call_2 (t:^t,a:^a,b:^b) : int = | |
(t ? (a) <- b ) |
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 Term<'a>() = class end | |
type Tuples = Tuples with | |
static member inline (?<-) (_ : Tuples, _ : Term<_>, _ : Term<_>) = 0 | |
static member inline (?<-) (_ : Tuples, (_:Term<_>,_:Term<_>),(_:Term<_>, _:Term<_>)) = 2 | |
static member inline (?<-) (_ : Tuples, a:bool, b:bool) = 3 | |
let inline call_2 (t:^t,a:^a,b:^a) : int = | |
(t ? (a) <- b ) | |
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 | |
open Microsoft.FSharp.Quotations | |
open Microsoft.FSharp.Quotations.Patterns | |
// Helper active patters for System.Type | |
let (|Arrow|_|) (t : Type) = | |
if t.IsGenericType && t.GetGenericTypeDefinition() = typedefof<_ -> _> then | |
let args = t.GetGenericArguments() | |
Some (args.[0], args.[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
#include <iostream> | |
using namespace std; | |
int foo() | |
{ | |
auto flatMap = [](auto f, auto s) { return [=](auto k) { return s([=](auto x) { f(x)(k); }); }; }; | |
auto map = [](auto f, auto s) { return [=](auto k) { s([=](auto x) { k(f(x)); }); }; }; | |
auto filter = [](auto p, auto s) { return [=](auto k) { s([=](auto x) { if(p(x)) k(x); }); }; }; | |
auto sum = [](auto k) { int sum = 0; k([&](int x) { sum += x; }); return sum; }; |
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 | |
interface Bool | |
and False = False with | |
interface Bool | |
type And = And with | |
static member inline (?<-) (True, And, True) = True | |
static member inline (?<-) (True, And, False) = False |
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 "on" | |
let inline readAllHashes nSkip nSentences = | |
sentencesFile | |
|> File.ReadLines | |
|> Stream.ofSeq | |
|> Stream.skip nSkip | |
|> Stream.take nSentences | |
|> Stream.map(fun line -> | |
let separatorIndex = line.IndexOf(' ') |
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> = ('T -> unit) -> unit -> bool | |
let inline ofArray (source : 'T []) : Stream<'T> = | |
fun iterf -> | |
let i = ref 0 | |
fun () -> | |
let flag = !i < source.Length | |
if not flag then | |
false |
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 sum (f : 'T -> int -> int) (array : 'T[]) = | |
let mutable sum = 0 | |
for i = 0 to array.Length - 1 do | |
sum <- sum + f array.[i] i | |
sum | |
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 Grouping<'T> = { IndexRef : int ref; ArrayRef : 'T [] ref } | |
let rec groupingAdd (value : 'T) (grouping : Grouping<'T>) = | |
let indexRef = grouping.IndexRef | |
let arrayRef = grouping.ArrayRef | |
let array = !arrayRef | |
if Object.ReferenceEquals(array, null) then | |
groupingAdd value grouping | |
else | |
let index = Interlocked.Increment(indexRef) |
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 | |
#r "bin/Release/Streams.Core.dll" | |
open Nessos.Streams.Core | |
let data = [|1..10000000|] |> Array.map (fun i -> int64 <| (i % 1000000)) | |
#r "../../packages/FSharp.Collections.ParallelSeq.1.0/lib/net40/FSharp.Collections.ParallelSeq.dll" | |
open FSharp.Collections.ParallelSeq |