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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Miljöinfo</title> | |
<meta charset="utf-8" /> | |
</head> | |
<style> | |
.node { | |
fill: #f15; |
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
// simple | |
const future = f => ({ | |
fork: g => f(g), | |
map: g => future(k => f(l => k(g(l)))), | |
flatMap: g => future(k => f(l => g(l).apply(k))) | |
}) | |
const getHttp = callback => { | |
const id = Math.floor(Math.random() * 5000 + 1000) | |
setTimeout(() => callback(`hej ${id}`), id) |
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
class MonadWriter<T, V> { | |
private v:T; | |
private log:V[]; | |
constructor(v:T, log:V[] | V) { | |
this.v = v; | |
if(log instanceof Array) | |
this.log = log; | |
else | |
this.log = [log]; |
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
class Reader<E, A> { | |
private constructor(protected k) {} | |
Run = (e: E): A => this.k(e); | |
Bind = <B>(f: (a: A) => Reader<E, B>): Reader<E, B> => | |
new Reader(e => f(this.k(e)).Run(e)); | |
Map = <B>(f: (a: A) => B): Reader<E, B> => new Reader(e => f(this.k(e))); | |
static Ask = <E, A>(): Reader<E, A> => new Reader(x => x); | |
static Asks = <E, A>(f: (a: E) => A): Reader<E, A> => new Reader(f); | |
static Unit = <E, A>(f: A): Reader<E, A> => new Reader(() => 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
class State { | |
private constructor(protected state) {} | |
Map = f => | |
new State(s => { | |
var prev = this.state(s); | |
return { value: f(prev.value), state: prev.state }; | |
}); | |
Join = () => |
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 rec minfrom = (a, n, xs) => { | |
let b = a + 1 + n/2; | |
let (us, vs) = List.partition(fun (x) => x < b, xs); | |
let m = List.length(us); | |
if(n == 0) | |
a | |
else if(m == b - a) | |
minfrom(b, n - m, vs) | |
else |
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
function minfree(xs) { | |
var _a = 0; | |
var _n = List.length(xs); | |
var _xs = xs; | |
while(true) { | |
var xs$1 = _xs; | |
var n = _n; | |
var a = _a; | |
var b = (a + 1 | 0) + (n / 2 | 0) | 0; | |
var match = List.partition((function(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 alias Config = | |
{ httpEndpoint : String | |
, portNumber : Int | |
} | |
type alias Person = | |
{ name : String | |
, address : String | |
} |
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
half : Int -> Writer Int String | |
half n = | |
tell ("halved " ++ (toString n)) >>= \_ -> return (n // 2) | |
use = | |
half 8 >>= half |> runReader | |
-- => (2, ["halved 4", "halved 8"]) |
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
// Using the super easy to use https://github.com/Zaid-Ajaj/Npgsql.FSharp | |
open System | |
open Npgsql.FSharp | |
type User = { | |
UserId : int | |
UserName: string | |
} |