Skip to content

Instantly share code, notes, and snippets.

@kevinmoran
kevinmoran / SquirrelNoise5.hpp
Created July 22, 2022 22:45
Improvement on Squirrel3 noise-based RNG by Squirrel Eiserloh (https://twitter.com/SquirrelTweets/status/1421251894274625536)
//-----------------------------------------------------------------------------------------------
// SquirrelNoise5.hpp
//
#pragma once
/////////////////////////////////////////////////////////////////////////////////////////////////
// SquirrelNoise5 - Squirrel's Raw Noise utilities (version 5)
//
// This code is made available under the Creative Commons attribution 3.0 license (CC-BY-3.0 US):
@gusty
gusty / memoization.fsx
Last active April 28, 2021 17:19
Polyvariadic Memoization
open System.Collections.Concurrent
type T = T with static member getOrAdd (cd:ConcurrentDictionary<_,'t>) (f:_ -> _) k = cd.GetOrAdd (k, f)
let inline memoize (f:'``(T1 -> T2 -> ... -> Tn)``): '``(T1 -> T2 -> ... -> Tn)`` = (T $ Unchecked.defaultof<'``(T1 -> T2 -> ... -> Tn)``>) f
type T with
static member ($) (_:obj, _: 'a -> 'b) = T.getOrAdd (ConcurrentDictionary ())
static member inline ($) (T, _:'t -> 'a -> 'b) = T.getOrAdd (ConcurrentDictionary ()) << (<<) memoize