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 (>>) f g a = a |> f |> g | |
let list_all = Sys.readdir >> Array.to_list >> List.filter Sys.is_directory | |
let rec read_all handle = | |
match Unix.readdir handle with | |
| "." | ".." -> read_all handle | |
| item -> item :: read_all handle | |
| exception End_of_file -> [] |
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 fork (f, g) x = (f x, g x) | |
let unzip list = fork (List.map fst, List.map snd) list |
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
(* (('a * 'b as 'a) * 'b) list -> 'a *) | |
let rec maximum xs = | |
let aux xs = | |
match xs with | |
| [(a,b)] -> (a,b) | |
| (a, b) :: xs -> | |
let (a', b') = maximum xs in | |
if b > b' then | |
(a, b) |
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
#lang racket/base | |
(require (rename-in racket/match) | |
(for-syntax racket/base)) | |
(define-match-expander zero | |
(λ (stx) #'0) | |
(λ (stx) #'0)) | |
(define-match-expander succ |
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
#lang racket | |
(define (compress uncompressed) | |
(let ([table (for*/hash ([i (in-range 256)] | |
[str (in-value (string (integer->char i)))]) | |
(values str i))]) | |
(for*/fold ([w ""] | |
[size 256] | |
[result null] | |
[tbl table] #:result `(,result . ,table)) |
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
#lang typed/racket | |
(define-type Hungry (Rec X (Natural -> X))) | |
(: f Hungry) | |
(define (f _) f) | |
(define-type (Stream X) (Rec A (Void -> (List Natural A)))) | |
; U-combinator (self application) |
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 subsequence longer shorter = | |
let rec inner l s = | |
match l, s with | |
| l :: ls, s :: ss when l = s -> inner ls ss | |
| _ :: ls , _ :: _ -> inner ls shorter | |
| [], _ -> false | |
| _, [] -> true | |
in | |
inner longer shorter | |
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 rec transpose xss = | |
match xss with | |
| [] :: _ | [] -> [] | |
| xs :: xss -> | |
let hds = List.map List.hd xss in | |
let tls = List.map List.tl xss in | |
let hd = List.hd xs in | |
let tl = List.tl xs in | |
(hd :: hds) :: transpose (tl :: tls) |
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 rec min count counts = | |
if count = 0 then 0 | |
else if not (List.contains count counts) then | |
0 | |
else | |
1 + min (count - 1) counts | |
let minDeletions (str : string) = | |
let step m elem = |
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 pattern = | |
| Char of char * pattern | |
| Any of pattern | |
| Wildcard of pattern | |
| End | |
let parsePattern (str: string) = | |
let str = [for s in str do s] | |
let folder c pat = | |
match c with |