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 Num<'a> = { | |
add : 'a -> 'a -> 'a; | |
subtract : 'a -> 'a -> 'a; | |
multiply : 'a -> 'a -> 'a; | |
divide : 'a -> 'a -> 'a; | |
} | |
type System.Int32 with | |
static member NumInstance () = | |
{ |
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
{-# LANGUAGE TypeOperators, ConstraintKinds, TypeFamilies #-} | |
import Data.Type.Equality | |
-- if we have two functions | |
-- a -> b | |
-- a' -> b' | |
-- and a proof that the function types are the same | |
-- then b must equal b' | |
proof1 :: |
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 a = fun b -> b // ok : ('a -> 'a) * int | |
, 2 | |
let b = fun b -> b // syntax error | |
, 2 | |
let c = fun b -> b // syntax error | |
, 2 | |
let d = fun b -> b // syntax 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
using System; | |
using System.Diagnostics; | |
using System.IO; | |
using System.Linq; | |
using System.Security.AccessControl; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace AtomicAppend | |
{ |
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
using System; | |
using System.Collections.Generic; | |
namespace TypeTree | |
{ | |
public interface IGet<out T> | |
{ | |
T Get { get; } | |
} |
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
// direct-ish translation | |
let allOrNone (xs : 'a option list) : 'a list option = | |
List.foldBack | |
(fun x st -> x |> Option.bind (fun x -> st |> Option.bind (fun st -> Some (x::st)))) | |
xs | |
(Some []) | |
// shorter | |
let allOrNone2 (xs : 'a option list) : 'a list option = | |
List.foldBack |
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 | |
type OnceLazy (action : unit -> unit) = | |
let it = Lazy(action, LazyThreadSafetyMode.ExecutionAndPublication) | |
member this.Force() = it.Force() | |
type Once (action : unit -> unit) = | |
let mutable performed = 0 | |
member this.Force() = |
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
// First, the validation type (applicative only): | |
type Validation<'e, 't> = | |
| ErrorCollection of 'e list | |
| Validated of 't | |
let (<*>) (f : Validation<'e, 'a -> 'b>) (v : Validation<'e, 'a>) : Validation<'e, 'b> = | |
match f, v with | |
| ErrorCollection e1, ErrorCollection e2 -> ErrorCollection (List.append e1 e2) | |
| ErrorCollection e1, _ -> ErrorCollection e1 | |
| _, ErrorCollection e2 -> ErrorCollection e2 |
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
internal struct TableIndex | |
{ | |
public readonly byte Value; | |
public TableIndex(byte value) | |
{ | |
Value = value; | |
} | |
} |
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
[StructLayout(LayoutKind.Explicit)] | |
public struct IntOrDouble | |
{ | |
private enum Type : byte | |
{ | |
Integral, | |
Floating | |
} | |
[FieldOffset(0)] |