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 a = | |
if true | |
then | |
1 | |
else | |
2 | |
|> (fun x -> sprintf "%i" x) | |
let (|>>) a b = a b |
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:Fenix.Dry" | |
module Translate = | |
open Fenix.Dry.Http | |
open Fenix.Dry.Http.HttpResponse | |
let translate q = | |
let body = | |
System.Text.Json.JsonSerializer.Serialize({| text = [|q|]; target_lang = "EN-US"; source_lang = "NB" |}) | |
let resp = |
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
//Skapa griden, det är en tabell med sträng 1 på x och sträng 2 på y | |
let longest_common_substring (word_a:string) (word_b:string) = | |
let cell = Array.init word_a.Length (fun _ -> Array.init word_b.Length (fun _ -> 0)) | |
for i = 0 to word_a.Length - 1 do | |
for j = 0 to word_b.Length - 1 do | |
if word_a[i] = word_b[j] then | |
if i > 0 && j > 0 then | |
cell[i][j] <- cell[i-1][j-1] + 1 |
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 | |
let inline middle a b = min a b + (abs (a - b) / (LanguagePrimitives.GenericOne + LanguagePrimitives.GenericOne)) | |
type Point = { x:int; y:int } | |
module Point = | |
let create x y ={ x = x; y = y } | |
let middle p1 p2 = create (middle p1.x p2.x) (middle p1.y p2.y) | |
let a = 2.0**2.0 | |
let pow n p = System.Math.Pow(n, p) |
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 private mapRequest (context : Microsoft.AspNetCore.Http.HttpContext) : Svea.Dry.Http.HttpRequest = | |
if context.Request.HasFormContentType then | |
let newStream : System.IO.Stream = | |
let ms = new System.IO.MemoryStream() | |
use sw = new System.IO.StreamWriter(ms, System.Text.Encoding.UTF8, 4096, true) | |
let mutable isFirst = true | |
for item in context.Request.Form do | |
sw.Write(sprintf "%s=%s" (System.Web.HttpUtility.UrlEncode(item.Key)) (item.Value |> Seq.map (fun x -> System.Web.HttpUtility.UrlEncode(x)) |> String.concat ",")) | |
if isFirst then |
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
//LibA.dll 1.0 | |
module LibA = | |
let helloWorld name = sprintf "Hello there %s" name | |
//LibB.dll | |
module LibB = | |
let helloThere name = sprintf "(Through LibB) %s" (LibA.helloWorld name) | |
//App | |
LibB.helloThere "Micke" |
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
type Transaction<'a> = string -> 'a | |
module Transaction = | |
let map<'a,'b> (mapper:'a -> 'b) (t:Transaction<'a>) : Transaction<'b> = | |
(fun x -> mapper (t x)) | |
let bind<'a,'b> (binder:'a -> Transaction<'b>) (t:Transaction<'a>) : Transaction<'b> = | |
(fun x -> binder (t x) x) | |
let execute connectionString (t:Transaction<'a>) = | |
t ConnectionString | |
type SqlReader<'state, 'element> = |
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
type Rec = { A : int; B : string } | |
let customServiceSchema : JsonSchemaType<Rec> = | |
recordSchema<Rec> "My Record" "" | |
[| | |
qouteField "id" "" SchemaJSON.int32 <@ fun x -> x.A @> | |
qouteField "status" "" SchemaJSON.string <@ fun x -> x.B @> | |
|] |
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
type CircularBuffer<'b>(bufferSize) = | |
let buffer : 'b option array = Array.init bufferSize (fun _ -> None) | |
let mutable currentIndex = bufferSize - 1 | |
let lockObj = System.Object() | |
member x.Add item = | |
lock (lockObj) | |
(fun () -> | |
let newIndex = |
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 inline fold f a (xs: _ []) = | |
let mutable a = a | |
for i=0 to xs.Length-1 do | |
a <- f a xs.[i] | |
a | |
let afold f a (xs: _ []) = | |
let mutable a = a | |
for i=0 to xs.Length-1 do | |
a <- f a xs.[i] |
NewerOlder