Skip to content

Instantly share code, notes, and snippets.

View SchlenkR's full-sized avatar

SchlenkR SchlenkR

View GitHub Profile
//open System.IO
//Directory.GetFiles(@"C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\5.0.11", "*.dll")
//|> Array.map (fun f -> $"""#r "{Path.GetFileName(f)}" """)
//|> Array.iter (printfn "%s")
#I @"C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\5.0.11"
#r "Microsoft.AspNetCore.Antiforgery.dll"
#r "Microsoft.AspNetCore.Authentication.Abstractions.dll"
@SchlenkR
SchlenkR / MSFT.csv
Created October 12, 2021 18:25
Für Vadim - FSharp.Data / CsvProvider
Date Open High Low Close Volume
9-Oct-17 75.97 76.55 75.86 76.29 11386502
6-Oct-17 75.67 76.03 75.54 76.00 13959814
5-Oct-17 75.22 76.12 74.96 75.97 21195261
4-Oct-17 74.09 74.72 73.71 74.69 13317681
3-Oct-17 74.67 74.88 74.20 74.26 12190403
2-Oct-17 74.71 75.01 74.30 74.61 15304762
29-Sep-17 73.94 74.54 73.88 74.49 17079114
28-Sep-17 73.54 73.97 73.31 73.87 10883787
27-Sep-17 73.55 74.17 73.17 73.85 19375099
open System
let tryParse (s: string) = Nullable(5.0)
let div (a: float) (b: float) = Nullable 10.0
let add a b = a + b
let num1 = tryParse "5.0"
type Update<'env, 'model, 'result> = 'env -> 'model -> 'model * 'result
[<AutoOpen>]
module UpdateOpens =
let inline zero env model = model,()
let getModel () : Update<'e, 'm, 'm> = fun _ model -> model,model
let getEnv () : Update<'e, 'm, 'e> = fun env model -> model,env
let getAll () : Update<'e, 'm, 'e * 'm> = fun env model -> model,(env,model)
let updateModel (newModel: 'm) : Update<'e, 'm, unit> = fun env model -> newModel,()
@SchlenkR
SchlenkR / Builder.fsx
Created September 27, 2020 15:55
F# Standard Builder Methods (Template)
// stolen from: https://fsharpforfunandprofit.com/posts/computation-expressions-builder-part6/
type WhateverBuilder() =
member this.Bind(m, f) = m f
member this.Return(x) = x
member this.ReturnFrom(x) = x
@SchlenkR
SchlenkR / SieveOfEratosthenes.fsx
Created August 16, 2020 08:22
Performance comparison of different implementations
// R imperative version (count prime numbers)
// sieb4 <- function(N) {
//
// if (N < 2L) return(integer())
// if (N == 2L) return(2L)
// toCheck <- seq_len(N)
// toCheck[1L] <- 0L
// toCheck[c(FALSE, TRUE)] <- 0L
//
@SchlenkR
SchlenkR / forComprehension.cs
Last active June 8, 2020 07:28
What "SelectMany", "For statements" and "from / for expressions" have in common
var l1 = new[]
{
new
{
name = "Jana",
projects = new[] {"p1", "p3"}
},
new
{
name = "Ronald",
@SchlenkR
SchlenkR / RecordImplementsInterface.fsx
Created May 14, 2020 14:58
An F# record that implements an interface
type IDisplayable =
abstract GetDisplayText: unit -> string
type Person =
{ age: int
name: string }
interface IDisplayable with
member x.GetDisplayText() = x.name
let showValue (x: IDisplayable) =
@SchlenkR
SchlenkR / curryN.fsx
Last active April 18, 2020 19:10
CurryN: An example of how to deal with generic n argument functions
module CurryN =
open System
module Constraints =
/// Constrain 't to be a nested tuple of <'t1,'t2,'t3,'t4,'t5,'t6,'t7,'tr>
let inline whenNestedTuple (t: 't) =
(^t: (member Item1: 't1) t), (^t: (member Item2: 't2) t), (^t: (member Item3: 't3) t), (^t: (member Item4: 't4) t), (^t: (member Item5: 't5) t), (^t: (member Item6: 't6) t), (^t: (member Item7: 't7) t), (^t: (member Rest: 'tr) t)
type 'a Foo = Foo of 'a
module Foo =
let ofValue (a : 'a) : 'a Foo = Foo a
let apply (a : 'a Foo) (f : ('a -> 'b) Foo) : 'b Foo =
let (Foo f) = f
let (Foo a) = a
Foo (f a)