Skip to content

Instantly share code, notes, and snippets.

@mrange
mrange / 0.md
Last active Dec 6, 2020
F# Advent 2020, Dec 6 - Church Encoded Lists
View 0.md

F# Advent 2020, Dec 6 - Church Encoded Lists

Introduction

The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise

Edsger W. Dijkstra

This is my contribution to F# Advent Calendar in English. Thanks to Sergey Tihon for making sure this happens every year.

@TeaDrivenDev
TeaDrivenDev / FsAdvent2019.md
Last active Dec 29, 2019
FsAdvent post for 2019
View FsAdvent2019.md

Paying It F#rward

This article is an entry in the 2019 F# Advent Calendar in English. Thanks to Sergey Tihon for organizing it, as always!

Note: This belongs on my blog, but some things are broken there right now, probably due to changes to GitHub Pages in recent years, so I'm publishing this here for now to at least get a reliable output.

The F# community, while small compared to those of many other languages, is known to be exceedingly open and helpful to beginners. I experienced this myself when I started learning the language nearly six years ago, and people (especially the F# MVPs) were always quick and eager to answer my newbie questions on Twitter, or wrote extensive answers on Stack Overflow or Code Review. Havi

@mrange
mrange / README.md
Last active Aug 18, 2020
[F#] Implementing Coroutines (async/await) using continuations
View README.md

[F#] Implementing Coroutines (async/await) using continuations

Coroutines or async/await is not a new concept as it was named in 1958 by Melvin Conway. Coroutines had support in languages such as Simula(1962), Smalltalk(1972) and Modula-2(1978) but I think one can argue that coroutines came into mainstream with C# 5(2012) when Microsoft added async/await to C#.

The problem with subroutines

A thread can only execute a single subroutine at a time as a subroutine starts and then runs to completion. In a server environment subroutines can be problematic as in order to service connections concurrently we would usually would start a thread per connection, this was the idiom a few years ago. A thread depending on the operating system and settings needs about 1 MiB of user stack space meaning 1,024 threads needs 1 GiB of for just user stack space. In addition there's the cost of kernel stack space, book-keeping and scheduling of threads. This drives cost of VM/hardwa

@mrange
mrange / README.md
Last active May 20, 2019
[F#/OCaml] Implementing a data streams library using a bunch of one-liners
View README.md

[F#/OCaml] Implementing a data streams library using a bunch of one-liners

A few years ago when I read the presentation motivating the design behind Nessos Streams I was struck by the beauty of simplistic push streams.

type PushStream<'T> = ('T -> bool) -> bool

LINQ (in .NET) is a pull stream, ie we pull values out of the stream by calling MoveNext + Current. One of the problems with pull streams is the constant checking "Are we done?" at each level in the stream.

@mrange
mrange / on-tail-recursion.md
Last active Jun 7, 2020
On the topic of tail calls in .NET
View on-tail-recursion.md

On the topic of tail calls in .NET

Let's say you have implemented a small data pipeline library to replace LINQ.

module TrivialStream =
  type Receiver<'T> = 'T            -> unit
  type Stream<'T>   = Receiver<'T>  -> unit

  module Details =
View assert-on-steroids.md

Assert On Steroids

I find it useful to have assert statements in my code. It has several benefits:

  • Self documents code expectations
  • Establishes boundary checks between component
  • Helps to pinpoint problems by failing fast, especially when you just started dealing with a new library
  • Here is a good summary on using assertions.

In a dream world all this can be addressed by sophisticated type system but we all know it’s not going to happen any time soon.

@swlaschin
swlaschin / ndcoslo17_fp_track.md
Created Jul 5, 2017
Functional Track talks from NDC Oslo 2017
View ndcoslo17_fp_track.md

Functional Track talks from NDC Oslo 2017

Also, here is the list of all videos from NDC Oslo 2017:

Wednesday 2017-06-14

@udalov
udalov / getKType.kt
Last active Mar 16, 2021
DEPRECATED example how to obtain KType instance from reified T. Please use "typeOf" since 1.3.40!
View getKType.kt
import java.lang.reflect.*
import kotlin.reflect.KClass
import kotlin.reflect.KType
import kotlin.reflect.KTypeProjection
import kotlin.reflect.KVariance
import kotlin.reflect.full.createType
// --- Interface ---
inline fun <reified T : Any> getKType(): KType =
@isaksky
isaksky / Working-with-SQL-syntax-trees-in-F.md
Last active Dec 14, 2019
Working with SQL syntax trees in F#
View Working-with-SQL-syntax-trees-in-F.md

Working with SQL syntax trees in F#

Update 12/15/2016 - Added Sql generation

Welcome to my blog post for #FsAdvent 2016.

If you're using a relational database, as your application grows in size, at some point you may find yourself looking for an SQL parser. This can give you lots of leverage, for example allowing you to:

  • Do permission checks on queries before executing them
  • Rewrite incorrect or inefficient queries
@mrange
mrange / fsharp_advent_2016_12_10.md
Last active Dec 14, 2019
F# Advent 2016 (English) - December 10 - Implementing a persistent hash map.
View fsharp_advent_2016_12_10.md