Skip to content

Instantly share code, notes, and snippets.

@Savelenko
Savelenko / Samples.fs
Last active April 4, 2021 15:46
F# GADT Sample model
module Samples
open TypeEquality
(* Generic data needed for all samples. *)
type Identifier = Identifier of int64
type Site = Site of string
// Together
@TheAngryByrd
TheAngryByrd / ParallelAsyncBuilder.fs
Last active January 10, 2022 14:44
Async computation allowing for parallel execution asyncs when using applicatives (and! syntax)
namespace AsyncHelpers
type Async =
static member map f x =
async.Bind(x, fun v -> async.Return(f v))
/// <summary>
/// Executes two asyncs concurrently and returns a tuple of the values
/// </summary>
/// <param name="a1">An async to execute</param>
@Savelenko
Savelenko / ExistentialEngines.fs
Last active June 27, 2024 18:57
F# existential types
// The engine interface and helpers
type IEngine<'a,'b> =
abstract member Capacity : int // Does not depend on 'a or 'b; just an example
// Some other stuff here possible depending on 'a and 'b
/// A function which works on any engine polymorphically and returns a result of type 'r'. Needed because
/// F# does not support higher-ranked types (not the same as HKT!) in regular functions. This does work in members.
type EngineFunction<'r> =
abstract member Apply : IEngine<'a,'b> -> 'r
@Savelenko
Savelenko / GADTMotivation.fs
Last active June 4, 2024 14:40
Motivated simulation of GADTs in F#, quite motivational
module GADTMotivation
(*
Here is a simple motivational example for GADTs and their usefulness for library design and domain modeling. Suppose we
need to work with settings which can be displayed and adjusted in a GUI. The set of possible setting "types" is fixed
and known in advance: integers, strings and booleans (check-boxes).
The GUI should show an example value for each possible setting type, e.g. 1337 for an integer setting and "Hello" for a
string setting. How can we model this small domain of setting types and computing example values?
*)

Thoughts on project files

I missed last night's ASP.NET Community Standup on account of being shattered after a long day and falling asleep. Then I checked Twitter on the train this morning and discovered that the .NET world had, apparently, been burned to the ground by marauding Microsofties (again). It seemed to have something to do with project files, JSON vs XML, and suchlike.

Finally, lunchtime happened and I could watch the recording of the standup, and I got to understand what everyone was on about. In case you've missed it:

The TL;DR history

  1. In the beginning, there was make, and Gates did not own make, so Gates said "Let there be MSBuild" and there was MSBuild.
  2. And MSBuild used the *.*proj files from Visual Studio as its inputs, which were formed of terrible XML, and verily it was impossible to use without a Visual Studio license.
/// A tic-tac-toe piece, or the absence thereof.
type Piece = U | X | O
/// Tic-tac-toe board position.
type Position = { X : int; Y : int }
[<AutoOpen>]
module GameModule =
/// A tic-tac-toe game implemented as a Pure ADT.
@jbevain
jbevain / Demo.fs
Last active February 17, 2023 20:40
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.CSharp
open Microsoft.CodeAnalysis.CSharp.Syntax
open FSharp.CodeAnalysis.CSharp.Patterns
// full form for the node, with SyntaxKind and tokens
let fullForm (n: CSharpSyntaxNode) =
match n with
| BinaryExpressionSyntax(_, LiteralExpressionSyntax(_), _, _) -> ()