I | Δ(I) | I | Δ(I) |
---|---|---|---|
(0,⊥) | (0,⊥) | (1,⊥) | (1,⊥) |
(⊥,0) | (⊥,0) | (⊥,1) | (⊥,1) |
(0,0) | (0,0) | (1,1) | (1,1) |
(0,1) | (0,0), (1,1) | (1,0) | (0,0), (1,1) |
I | Δ(I) |
---|---|
(0,⊥,⊥) | (0,⊥,⊥), (1,⊥,⊥), (2,⊥,⊥) |
(⊥,0,⊥) | (⊥,0,⊥), (⊥,1,⊥), (⊥,2,⊥) |
(⊥,⊥,0) | (⊥,⊥,0), (⊥,⊥,1), (⊥,⊥,2) |
(0,0,⊥) | (0,1,⊥), (1,0,⊥), (0,2,⊥), (2,0,⊥), (2,1,⊥), (1,2,⊥) |
(0,⊥,0) | (0,⊥,1), (1,⊥,0), (0,⊥,2), (2,⊥,0), (2,⊥,1), (1,⊥,2) |
(⊥,0,0) | (⊥,0,1), (⊥,1,0), (⊥,0,2), (⊥,2,0), (⊥,2,1), (⊥,1,2) |
(0,0,0) | (0,1,2), (0,2,1), (1,0,2), (1,2,0), (2,0,1), (2,1,0) |
This file contains 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 readInt (s:string) = | |
match System.Int32.TryParse s with | |
| true,i -> Some i | |
| _ -> None | |
type Opt<'a> = Opt of name:string * defaultValue:'a option * read:(string -> 'a option) | |
with | |
static member Name<'a> (Opt(n,_,_) : Opt<'a>) = n | |
static member Read<'a> (Opt(_,_,r) : Opt<'a>) = r | |
static member Default<'a> (Opt(_,d,_) : Opt<'a>) = d |
This file contains 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
/// A probability is a number between 0 and 1 inclusive. | |
type Prob = float | |
/// A distribution is a sequence of outcome-probability pairs such that the | |
/// probabilities sum to 1. | |
type Dist<'a> = D of seq<'a * Prob> | |
/// A spread takes a sequence of elements and assigns probabilities. | |
type Spread<'a> = 'a list -> Dist<'a> |
This file contains 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
/// A value together with its derivative. | |
[<NoComparison>] | |
type D<'a> = D of 'a * 'a | |
module D = | |
[<GeneralizableValue>] | |
let inline GenericTwo () = | |
LanguagePrimitives.GenericOne + LanguagePrimitives.GenericOne |
This file contains 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 System.Threading | |
/// A dependant variable. | |
type DVar<'a> = private { cell : 'a ref ; event : Event<'a> } | |
/// Operations on dependant variables. | |
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>] | |
module DVar = | |
This file contains 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
/// Operations on Berkley sockets. | |
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>] | |
module Socket = | |
/// Executes an async socket operation. | |
let exec (alloc:unit -> SocketAsyncEventArgs, free:SocketAsyncEventArgs -> unit) (config:SocketAsyncEventArgs -> unit) (op:SocketAsyncEventArgs -> bool) (map:SocketAsyncEventArgs -> 'a) = | |
Async.FromContinuations <| fun (ok, error, _) -> | |
let args = alloc () |
This file contains 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
/// An async observer. | |
type AsyncObserver<'a> = 'a option -> Async<unit> | |
module AsyncObserver = | |
let inline post a (obs:AsyncObserver<'a>) = obs (Some a) | |
let inline stop (obs:AsyncObserver<'a>) = obs None | |
let contramap (f:'b -> 'a) (o:AsyncObserver<'a>) : AsyncObserver<'b> = |
This file contains 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
// for http://www.fssnip.net/d2 | |
type Fold<'b> = Fold of f:('b -> obj -> 'b) * z:'b | |
with | |
static member inline ($) (Fold(_,z), HNil) = z | |
static member inline ($) (Fold(f,z), HCons(a,xs)) = f (Fold(f,z) |*| xs) a | |
// use |
This file contains 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 Hopac | |
open Hopac.Infixes | |
open Hopac.Job.Infixes | |
open Hopac.Extensions | |
type IoCh<'i, 'o> = Ch<'i * IVar<'o>> | |
module IoCh = | |
let create (f:'i -> Job<'o>) : Job<IoCh<'i, 'o>> = |