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
// One of the common annoyances when writing imperative code in F# is that the | |
// expression-based nature of the language makes it effectively impossible to | |
// break or return in the midst of a for-loop. This is an attempt to encode | |
// lightweight cancellation on top of native for loops. As usual, this is intended | |
// as a PoC and should not be considered seriously for production code. | |
module Seq = | |
open System.Collections | |
open System.Collections.Generic |
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
#time "on" | |
open System | |
open System.Collections.Generic | |
let gdata = [|for i in 1 .. 1000000 -> Guid.NewGuid()|] | |
let sdata = gdata |> Array.map string | |
// Real: 00:00:17.774, CPU: 00:00:17.703, GC gen0: 378, gen1: 61, gen2: 1 | |
let gmap = ref Map.empty<Guid, int> |
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
module Client = | |
let connectionString = Environment.GetEnvironmentVariable("CONN") | |
let session = new Session(connectionString) | |
let doA (a : A) = session.Send a | |
let doB (b : B) = session.Send b | |
type Client(connectionString : string) = |
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.Runtime.CompilerServices | |
type SymbolicException = | |
{ | |
Source : Exception | |
Stacktrace : string list | |
} | |
module SymbolicException = |
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
{ | |
"Success": { | |
"_flags": "subtype", | |
"subtype": { | |
"Case": "GenericTypeInstance", | |
"GenericDefinition": { | |
"Case": "NamedType", | |
"Name": "MBrace.Core.Builders+Bind@331-1", | |
"Assembly": { | |
"Name": "MBrace.Core", |
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.Reflection | |
open Microsoft.FSharp.Quotations | |
open Microsoft.FSharp.Quotations.Patterns | |
open Microsoft.FSharp.Quotations.DerivedPatterns | |
type MethodInfo with | |
/// Gets the underlying method definition | |
/// including the supplied declaring type and method type arguments |
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
type Test = | |
static member F<'T>(t : 'T option) = () | |
static member F<'T>(e : 'T -> 'T) = () | |
type Foo = { A : int } | |
type Bar = { A : int } | |
Test.F(fun (r:Foo) -> { r with A = 32 }) // type checks | |
Test.F(fun (r:Bar) -> { r with A = 32 }) // type checks | |
Test.F<Foo>(fun r -> { r with A = 32 }) // type error |
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
type Cont<'T> = ('T -> unit) -> (exn -> unit) -> unit | |
let ret t = fun sc _ -> sc t | |
let (>>=) f g = | |
fun sc ec -> | |
let sc' (t : 'T) = | |
match (try Choice1Of2 (g t) with e -> Choice2Of2 e) with | |
| Choice1Of2 g -> g sc ec | |
| Choice2Of2 e -> ec e |
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 run x = Async.RunSynchronously x | |
let runParallel (workflow : Async<'T>) = | |
[| for i in 1 .. 100 -> workflow |] | |
|> Async.Parallel | |
|> run | |
let a = async { return 42 } | |
let b = async { return run (async { return 42 })} |
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
// current type abbreviations in F# | |
type A = Guid | |
type B = Guid | |
let foo (x : A) = x.ToString() | |
let b = B.NewGuid() | |
foo(b) // type checks | |
// proposed newtype abbreviations | |
newtype A = Guid |