This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on http://nut-cracker.azurewebsites.net/blog/2011/11/07/functions-for-n-tuples/ | |
// Warning: This script has long compile times | |
// but as from F# 4.1 will work fine | |
// due to this fix: https://github.com/Microsoft/visualfsharp/pull/1682 in the compiler | |
open System | |
type Infinite<'a> = Infinite of 'a | |
module TupleInternalValues = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "nuget: FSharpPlus,1.2" | |
open FSharpPlus | |
open FSharpPlus.Math.Generic | |
type Ratio = | |
struct | |
val Numerator : bigint | |
val Denominator : bigint | |
new (numerator: bigint, denominator: bigint) = {Numerator = numerator; Denominator = denominator} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* =================================== | |
Code from my series of posts "Six approaches to dependency injection" | |
=================================== *) | |
open System | |
(* | |
## The requirements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unfortunatelly it stopped working in F# 4.1 after this PR https://github.com/Microsoft/visualfsharp/pull/1650 | |
// Will ask to revert it | |
type FoldArgs<'t> = FoldArgs of ('t -> 't -> 't) | |
let inline foldArgs f (x:'t) (y:'t) :'rest = (FoldArgs f $ Unchecked.defaultof<'rest>) x y | |
type FoldArgs<'t> with | |
static member inline ($) (FoldArgs f, _:'t-> 'rest) = fun (a:'t) -> f a >> foldArgs f | |
static member ($) (FoldArgs f, _:'t ) = f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let trampoline f c n = | |
let rec loop = function | |
| Choice1Of2 x -> x | |
| Choice2Of2 x -> loop (f x) | |
loop (Choice2Of2 (c,n)) | |
// Test | |
let factorial n = | |
let rec factorialT (current, n) = | |
if n = bigint 0 then Choice1Of2 current |
OlderNewer