This file contains hidden or 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 AATree a = E | T(Number, AATree a, a, AATree a) | |
| let empty = E | |
| let isEmpty = [E → True | T _ → False] | |
| let rec count = | |
| [ E → 0 | |
| | T(_, l, _, r) → count l + 1 + count r ] |
This file contains hidden or 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 zero = 0, 0, 0 | |
| let scale s (x, y, z) = s*x, s*y, s*z | |
| let add (x1,y1,z1) (x2,y2,z2) = x1+x2, y1+y1, z1+z2 | |
| let sub (x1,y1,z1) (x2,y2,z2) = x1-x2, y1-y1, z1-z2 | |
| let dot (x1,y1,z1) (x2,y2,z2) = x1*x2 + y1*y1 + z1*z2 | |
| let unitise u = scale (1/√(dot u u)) u | |
| type rec Scene = | |
| | Sphere | |
| | Bound(Array((Number, Number, Number), Number, Scene)) |
This file contains hidden or 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
| module Concestor(Key: Collections.HASH) : sig | |
| type 'v t | |
| val empty : unit -> 'v t | |
| val is_empty : 'v t -> bool | |
| val add : Key.t -> 'v -> 'v t -> 'v t | |
| val remove : Key.t -> 'v t -> 'v t | |
| val mem : Key.t -> 'v t -> bool | |
| val find : Key.t -> 'v t -> 'v | |
| val find_opt : Key.t -> 'v t -> 'v option |
This file contains hidden or 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 primes = | |
| [|3; 7; 13; 31; 61; 127; 251; 509; 1021; 2039; 4093; 8191; 16381; 32749; | |
| 65521; 131071; 262139; 524287; 1048573; 2097143; 4194301; 8388593; | |
| 16777213; 33554393; 67108859; 134217689; 268435399; 536870909; 1073741789; | |
| 2147483647|] | |
| let mods = | |
| [|(fun n -> n mod 3); | |
| (fun n -> n mod 7); | |
| (fun n -> n mod 13); |
This file contains hidden or 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
| # Upload files from this machine to another without clobbering. | |
| # Usage: | |
| # ./upload.sh <srcdir> <user@host> <dstdir> | |
| tar -cz $1 | ssh $2 "tar -kzxf - -C ${3}" |
This file contains hidden or 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.Threading | |
| /// Spawn a new Task. | |
| let task f x = | |
| Tasks.Task<_>.Factory.StartNew(fun () -> f x) | |
| module internal Internal = | |
| /// Compute "map f [i0, i2) |> reduce g" in parallel using divide and conquer. | |
| /// Assumes "f" is associative but does not assume that it is commutative. | |
| /// Therefore, this function can return "f (f 0 1) (f 2 3)" but not "f 1 0" etc. |
This file contains hidden or 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.Text.RegularExpressions | |
| let alphabet = ['a'..'z'] | |
| let edits1 (w: string) = | |
| seq { for i in 0 .. w.Length do | |
| if i < w.Length then | |
| yield w.[0..i-1] + w.[i+1..] // Delete | |
| if i < w.Length-1 then | |
| yield w.[0..i-1] + w.[i+1..i+1] + w.[i..i] + w.[i+2..] // Swap |
This file contains hidden or 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
| (* | |
| This tiny 211-line compiler converts programs written in a little ML dialect into 32-bit ARM | |
| assembly. | |
| This program is most easily run using FSI with flags to turn off FSI's output so the output | |
| of this program can be piped into a file: | |
| dotnet fsi --quiet --exec compiler7.fs >fib.s | |
| That file can then be compiled with: |
This file contains hidden or 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 mutable globalException : System.Exception = null // Compiler generated | |
| let myGlobal = | |
| if isNull globalException then // Compiler generated | |
| try // Compiler generated | |
| System.IO.File.ReadAllText "DoesNotExist.txt" | |
| with e -> // Compiler generated | |
| globalException <- e // Compiler generated | |
| Unchecked.defaultof<_> // Compiler generated | |
| else Unchecked.defaultof<_> // Compiler generated |
This file contains hidden or 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.Windows | |
| let goldenRatio = (1.0 + sqrt 5.0) / 2.0 | |
| let newBrush = | |
| let mutable hue = 0.0 | |
| fun () -> | |
| hue <- hue + System.Math.PI / goldenRatio | |
| let s x = byte(255.0 * x) | |
| let c x = 0.5 * (cos x + 1.0) |