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
#lang racket | |
(define-syntax-rule (define/memo (f x ...) e ...) | |
(define f | |
(let ([m (make-hash)]) | |
(λ (x ...) (hash-ref! m (list x ...) (λ () e ...)))))) | |
; memoized fibonacci | |
(define/memo (fib n) | |
(if (< n 2) n |
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
#lang typed/racket | |
(: f (case-> | |
[Number -> (-> Number)] | |
[(-> Number) -> Number])) | |
(define (f x) | |
(if (number? x) (λ () (- x)) (x))) |
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
(module list | |
(provide | |
[reverse ([l : (listof int?)] | |
. -> . | |
(and/c (listof int?) | |
(λ (r) (and (equal? (empty? l) (empty? r)) | |
(equal? (cons? l) (cons? r))))))] | |
[mk-list ([n : int?] | |
. -> . | |
(and/c (listof int?) |
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 top = N of int | S of string | |
let f input extra = | |
match input,extra with | |
| N m, (N n,_) -> m + n | |
| _, (N n,_) -> (match input with | |
| S s -> String.length s + n) | |
| _,_ -> 0 | |
let main i e = f i e |
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
#lang racket | |
;; String -> [Listof String] | |
;; return all rotations of a string | |
(define (>>n s) | |
;; rotate a string to the right | |
(define (>> s) | |
(string-append (substring s 1 (string-length s)) (substring s 0 1))) | |
(let-values ([(ss _) |
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
#lang racket/base | |
(define-syntax-rule (gc) | |
(begin (collect-garbage) (collect-garbage) (collect-garbage))) | |
(define N 10000000) | |
(printf "Immutable map:~n") | |
(let ([M (hash)]) | |
(printf " Write: ") | |
(gc) (time (for ([i N]) (set! M (hash-set M i #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
#lang racket/base | |
(begin | |
(define-syntaxes (struct:x x1 x? x-a x-b) (#%app values)) | |
(define-syntaxes | |
(x) | |
(#%app | |
make-self-ctor-checked-struct-info | |
(lambda () | |
(#%app |
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
#lang typed/racket | |
(define ∅ : (Setof Nothing) {set}) | |
(define ∪ set-union) | |
(define ∩ set-intersect) | |
(define ∋ set-member?) | |
(: fix : (∀ (X) (X → X) X → X)) | |
;; Compute `f`'s fixpoint starting from `x` | |
(define (fix f x) |
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
import scala.language.experimental.macros | |
import scala.reflect.macros.blackbox.Context | |
import scala.annotation.StaticAnnotation | |
import scala.annotation.compileTimeOnly | |
/** | |
This annotation turns a simple class declaration into a type-safe and unboxed Enum. | |
It does not attempt to be compatible with Java, because I have no respect for Java. | |
There is an example usage at the end of the file. | |
*/ |
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
import leon.lang._ | |
import leon.lang.synthesis._ | |
import leon.annotation._ | |
object BraunTree { | |
sealed abstract class Tree | |
case object Leaf extends Tree | |
case class Node(l: Tree, n: Int, r: Tree) extends Tree | |
def size(t: Tree): Int = t match { |
OlderNewer