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
#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
#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 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
(* (('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
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
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
type 'a recc = In of ('a recc -> 'a) | |
let out (In f) = f | |
let u f = out f f | |
let y g = | |
u (In (fun f -> g (out f f))) |
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 stack with an existential/abstract type 't *) | |
type 'a stack = | |
Stack: { to_list: 't -> 'a list; | |
of_list: 'a list -> 't; | |
empty: 't; | |
push: 'a -> 't -> 't; | |
pop: 't -> ('t * 'a) option } -> | |
'a stack | |
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
import Data.Vect | |
-- This is a paramorphism (aka primitive recursion) on Vectors | |
foldr : (motive : (k : Nat) -> Vect k a -> Type) -> | |
((l : Nat) -> (x : a) -> (xs : Vect l a) -> motive l xs -> motive (S l) (x :: xs)) -> | |
motive Z [] -> | |
(vec : Vect n a) -> | |
motive n vec | |
foldr {n = Z} motive step base [] = base | |
foldr {n = S k} motive step base (x :: xs) = step k x xs (foldr motive step base xs) |