Skip to content

Instantly share code, notes, and snippets.

type Attr = delegate of RenderTreeBuilder * int -> int
type Node = delegate of RenderTreeBuilder * int -> int
type NodeBuilder(name: string) =
static member Empty = Node(fun _sb x -> x)
member _.Name = name
using System;
using System.Collections.Generic;
using System.Linq;
var coll = Enumerable.Range(1, 10);
// We need to repeat "int" here, it can't be implied by IntAdd or IntMul :(
Console.WriteLine($"The sum is {AppendMany<IntAdd, int>(coll)}");
Console.WriteLine($"The product is {AppendMany<IntMul, int>(coll)}");
// A reply to: https://twitter.com/davidfowl/status/1282445306261471232
// This implements a connection of some kind that can be started and stopped asynchronously.
// We must ensure that we don't try to start it while it is stopping or vice-versa.
// A few internal types first...
/// Contains whatever state needs to be held on to while connected.
type private ConnectedState = { Id: int }
/// The state of the internal agent. Describes the current status of the connection,
open System.IO
open System.Threading.Tasks
open FSharp.Control.Tasks.TaskBuilder
open FSharp.Control.Tasks.V2
type UnitTaskBuilder() =
inherit TaskBuilderV2()
member _.Run(x) = base.Run(x) :> Task
let utask = UnitTaskBuilder()
open System.Text.Json
open System.Text.Json.Serialization
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
type MyUnion =
| Foo
| Bar of int * string
type Unions() =
open System.Text.Json
open System.Text.Json.Serialization
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
type MyRecord =
{
x: int
y: string
}
namespace Avalonia.Media.TextFormatting.Unicode
open Avalonia.Utility
[<Struct; IsByRefLike>]
type CodepointEnumerator =
val mutable text : ReadOnlySlice<char>
val mutable current : Codepoint
namespace Avalonia.Media.TextFormatting.Unicode
open Avalonia.Utility
[<Struct; IsByRefLike>]
type CodepointEnumerator(text: ReadOnlySlice<char>) =
let mutable text = text
let mutable current = Codepoint.ReplacementCodepoint
@Tarmil
Tarmil / Directory.Build.targets
Last active November 20, 2019 13:38
Override NuGet/Paket package references with local projects
<?xml version="1.0" encoding="utf-8"?>
<Project>
<!--
Override NuGet (or Paket) references with a set of local projects.
Usage:
* Add this file at the root above all your projects, so that they all gain the capability to override a package.
* In a solution where you want to override a package, add a file Directory.Build.props like the following:
<?xml version="1.0" encoding="utf-8"?>
<Project>
type User = { name: string; (* ... *) }
type UserId = int
type EndPoint<_> =
| [<EndPoint "GET /user/{id}">]
GetUser : id: UserId -> EndPoint<Json<User>>
| [<EndPoint "POST /user"; Json "userData">]
CreateUser : userData: User -> EndPoint<Json<UserId>>