Skip to content

Instantly share code, notes, and snippets.

module My.Blogs
open System
open System.Collections.Generic
open System.Web
open IntelliFactory.WebSharper.Sitelets
type Id = int
type Html = string
#lang racket
(define (quadratic a b c)
(let* ([det (- (* b b) (* 4 a c))]
[x1 (/ (- (sqrt det) b) (* 2 a))]
[x2 (/ (- (- (sqrt det)) b) (* 2 a))])
(vector x1 x2)))
type Regex<'T> =
| Choose of Regex<'T> * Regex<'T>
| Concat of Regex<'T> * Regex<'T>
| Empty
| Filter of ('T -> bool)
| Star of Regex<'T>
module NFA =
type State<'T> =
| Match
| Branch of State<'T> * State<'T>
| Read of ('T -> bool) * State<'T>
module NFA =
[<CustomEquality>]
[<CustomComparison>]
type State<'T> =
| Match
| Branch of Pair<'T>
| Read of int * ('T -> bool) * State<'T>
member this.Key =
module NFA =
let Compile regex =
let k = ref 0
let next () =
incr k
!k
let rec compile regex matched =
match regex with
| Choose (a, b) ->
module DFA =
open System.Collections.Generic
type State<'T> =
{
IsMatch : bool
States : Set<NFA.State<'T>>
Transitions : Dictionary<'T,State<'T>>
}
module DFA =
let rec nextState current token =
match current.Transitions.TryGetValue token with
| true, state -> state
| _ ->
let rec loop current next =
if Set.isEmpty current then getState next else
let min = Set.minElement current
let current = Set.remove min current
class Functor f where
fmap :: (a -> b) -> f a -> f b
instance Functor [] where
fmap = map
type Box<'T1,'T2> = { Value : obj }
module List =
let Box (list: list<'T>) : Box<list<obj>,'T> = { Value = list }
let Unbox (x: Box<list<obj>,'T>) : list<'T> = x.Value :?> _
type IFunctor<'T> =
abstract member Map : ('T1 -> 'T2) -> Box<'T,'T1> -> Box<'T,'T2>
let ListFunctor =