Skip to content

Instantly share code, notes, and snippets.

@espio999
espio999 / memoization.fsx
Created July 23, 2024 15:20
F# memoization module
module memoization
open System.Collections.Generic
open System.Collections.Concurrent
let memoization fn =
let cache = new Dictionary<_,_>()
printfn "counter: %A" cache.Count
fun arg ->
@espio999
espio999 / comparison.fsx
Created July 22, 2024 13:11
Performance comparison of Fibonacci number in F#
#load "fibonacci.fsx"
open fibonacci
open System.Diagnostics
let loop_start = 0
let loop_end = 40
let testloop fn =
let sw = new Stopwatch()
@espio999
espio999 / fibonacci.fsx
Last active July 22, 2024 13:02
F# fibonacci module
module fibonacci
open System.Collections.Generic
let rec fib n =
match n with
| 0 | 1 -> n
| n -> fib (n-1) + fib (n-2)
[<TailCall>]
@espio999
espio999 / pattern_matching_with_type_test.fsx
Created July 1, 2024 12:46
F# pattern matching - type test
type A() = class end
type B() = inherit A()
type C() = inherit A()
let evaluation (obj: A) =
match obj with
| :? B -> "It's a B"
| :? C -> "It's a C"
| :? A -> "It's a A"
| _ -> "nothing"
@espio999
espio999 / pattern_matching_with_type_annotation.fsx
Created July 1, 2024 12:41
F# pattern matching - type annotation
let detect1 x =
match x with
| 1 -> printfn "Found a 1!"
| (var1 : int) -> printfn "%d" var1
let my_list = [0..9]
for i in my_list do detect1 i
@espio999
espio999 / pattern_matching_practical_shorter.fsx
Last active July 1, 2024 12:44
F# pattern matching - identifier pattern for practical purpose - shorter
type Money = Money of decimal
let calcTax (Money price) = Money (price * 0.1m)
let p = Money 100m
calcTax p |> printfn "%A"
@espio999
espio999 / pattern_matching_understanding_shorter.fsx
Last active July 1, 2024 12:44
F# pattern matching - identifier pattern for understanding - shorter
type TypeMoney = CaseMoney of decimal
let calcTax (CaseMoney price) = CaseMoney (price * 0.1m)
let p = CaseMoney 100m
calcTax p |> printfn "%A"
@espio999
espio999 / pattern_matching_understanding.fsx
Last active July 1, 2024 12:43
F# pattern matching - identifier pattern for understanding
type TypeMoney = CaseMoney of decimal
let calcTax (param_price: TypeMoney) =
//let local_price = match param_price with CaseMoney local_p -> local_p
let local_price = match param_price with CaseMoney (local_p) -> local_p
CaseMoney (local_price * 0.1m)
let p = CaseMoney 100m
calcTax p |> printfn "%A"
@espio999
espio999 / pattern_matching_practical.fsx
Last active July 1, 2024 12:43
F# pattern matching - identifier pattern for practical purpose
type Money = Money of decimal
let calcTax (price: Money) =
let price = match price with Money p -> p
Money (price * 0.1m)
let p = Money 100m
calcTax p |> printfn "%A"
@espio999
espio999 / chatLZMA-twitter.py
Created September 2, 2023 14:51
chatLZMA-Twitter
import json
import lzma
import nltk
import random
nltk.download('twitter_samples')
my_filters = [
{"id": lzma.FILTER_LZMA2, "preset": 9 | lzma.PRESET_EXTREME},
]