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) |
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 Marvel | |
open System.Collections.Concurrent | |
open System.Collections.Generic | |
type Pid = int | |
type Op = { | |
op : string | |
sn : SN | |
} |
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
open System | |
open Microsoft.FSharp.Reflection | |
open Newtonsoft.Json | |
open Newtonsoft.Json.Converters | |
type OptionConverter() = | |
inherit JsonConverter() | |
override x.CanConvert(t) = | |
t.IsGenericType && t.GetGenericTypeDefinition() = typedefof<option<_>> |
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
/// <summary> | |
/// Utility methods for <see cref="System.Threading.Tasks.Task"/>. | |
/// </summary> | |
public static class TaskHelper | |
{ | |
/// <summary> | |
/// Returns a task which retries the task returned by the specified task provider. | |
/// </summary> | |
/// <typeparam name="TResult"></typeparam> | |
/// <param name="taskProvider">The task returning function.</param> |
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
/// 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
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 = | |
There is a great purely functional streaming/IO library in Scala called scalaz-stream. It is itself based upon a Haskell library called machines. They provide powerful abstractions to express compositional effectful computations. These libraries rely on certain type system features in both Scala and Haskell which are unavailable in F# - namely existential types and higher kinds. Higher kinds allow the monad representing the side-effects to be abstracted over. If however we specialize this to a specific monad, we can get around the lack of existentials as well.
Tomas Petricek created a type called asynchronous sequence which provides similar capabilities. The F# AsyncSeq
type is declared as follows:
type AsyncSeq<'a> = Async<AsyncSeqInner<'a>>
and AsyncSeqInner<'a> =
| Nil
| Cons of 'a * AsyncSeq<'a>