Skip to content

Instantly share code, notes, and snippets.

@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 =
@mrange
mrange / 0_FsTransducer2.fs
Last active May 22, 2018
Another take at Transducers
View 0_FsTransducer2.fs
module FsTransducers =
type Context =
{
mutable Continue : bool
}
static member New () : Context = { Continue = true }
type Initializer = Context -> unit
type Folder<'S, 'T> = 'S -> 'T -> 'S
type Completer<'S> = Context -> 'S -> 'S
type [<Struct>] Reducer<'S, 'T> = R of (Initializer*Folder<'S, 'T>*Completer<'S>)
View permutations.fs
let rec distribute e = function
| [] -> [[e]]
| x::xs' as xs -> (e::xs)::[for xs in distribute e xs' -> x::xs]
let rec permute = function
| [] -> [[]]
| e::xs -> List.collect (distribute e) (permute xs)
let generatePermutations r (vs : _ []) =
let inline swap f t =
View transformer.fs
module AnyTransformer =
type [<AbstractClass>] BadCause () =
class
abstract Describe : string
override x.ToString () = x.Describe
end
type [<Sealed>] MessageBadCause (msg: string) =
class
inherit BadCause ()
@mrange
mrange / mandelbrot.md
Last active Jun 2, 2021
The Computer Language Benchmarks Game - Mandelbrot
View mandelbrot.md

The Computer Language Benchmarks Game - Mandelbrot

Source code: https://github.com/mrange/benchmarksgame/tree/master/src/mandelbrot

  1. Update 2017-06-25 - Decided I could do a bit better with F# so I added an improved F# program that uses the .NET SSE
  2. Update 2017-07-01 - Reduced the overhead of bitmap allocation saving 9ms for 16000x16000 bitmaps
  3. Update 2017-07-06 - Improved the fast F# program by removing overy redundancy

Recently I discovered The Computer Language Benchmarks Game which intrigued me, especially the mandelbrot version.

@jchandra74
jchandra74 / PowerShell Customization.md
Last active Oct 17, 2021
PowerShell, Cmder / ConEmu, Posh-Git, Oh-My-Posh, Powerline Customization
View PowerShell Customization.md

Pimping Up Your PowerShell & Cmder with Posh-Git, Oh-My-Posh, & Powerline Fonts

Backstory (TLDR)

I work as a full-stack developer at work. We are a Windows & Azure shop, so we are using Windows as our development platform, hence this customization.

For my console needs, I am using Cmder which is based on ConEmu with PowerShell as my shell of choice.

Yes, yes, I know nowadays you can use the Linux subsystem on Windows 10 which allow you to run Ubuntu on Windows. If you are looking for customization of the Ubuntu bash shell, check out this article by Scott Hanselman.

@enricosada
enricosada / fsharp and .net core sdk status.md
Last active Mar 29, 2020
.NET Core sdk, msbuild, fsharp, fsc, etc
View fsharp and .net core sdk status.md

.NET Core sdk, msbuild, fsharp, fsc, etc

How to finish/polish the integration between msbuild based .net core sdk and f# (fsc, FscTask, etc)

This doc contains current issues i known and a proposed solution (already implemented in a PR, and works) on how to fix these (obv ihmo).

AFAIK all the solution i choose are based on where dotnet/sdk, microsoft/msbuild and dotnet/cli are going with development, and updated to latest release (preview4), and vnext in development now.

TL;DR

@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
@vietnt
vietnt / example.fs
Last active Dec 29, 2020
unsafe in f#
View example.fs
[<Struct;StructLayout(LayoutKind.Explicit, Pack=1,Size=32)>]
type Bucket =
struct
[<FieldOffset(0)>]val mutable Free : int64
[<FieldOffset(8)>]val mutable FreeCount: int
[<FieldOffset(12)>]val mutable Used: int
[<FieldOffset(16)>]val mutable Size: int
[<FieldOffset(20)>]val mutable Full: bool
end