Skip to content

Instantly share code, notes, and snippets.

@bryal
Created November 8, 2017 08:47
Show Gist options
  • Save bryal/f44dfb0b3e5d9a32c285d18dd43e67ea to your computer and use it in GitHub Desktop.
Save bryal/f44dfb0b3e5d9a32c285d18dd43e67ea to your computer and use it in GitHub Desktop.
(extern malloc (-> UInt (Ptr UInt8)))
(extern read_int64 (-> RealWorld (Cons Int64 RealWorld)))
(extern print_int64 (-> (Cons Int64 RealWorld) (Cons Nil RealWorld)))
(extern print_float64 (-> (Cons Float64 RealWorld) (Cons Nil RealWorld)))
(extern eq-int64 (-> (Cons Int64 Int64) Bool))
(extern lt-int64 (-> (Cons Int64 Int64) Bool))
(extern gt-int64 (-> (Cons Int64 Int64) Bool))
(extern mul-int64 (-> (Cons Int64 Int64) Int64))
(extern div-int64 (-> (Cons Int64 Int64) Int64))
(extern add-int64 (-> (Cons Int64 Int64) Int64))
(extern sub-int64 (-> (Cons Int64 Int64) Int64))
(define (= x y) (eq-int64 (cons x y)))
(define (< x y) (lt-int64 (cons x y)))
(define (> x y) (gt-int64 (cons x y)))
(define (* x y) (mul-int64 (cons x y)))
(define (/ x y) (div-int64 (cons x y)))
(define (+ x y) (add-int64 (cons x y)))
(define (- x y) (sub-int64 (cons x y)))
(define read-int64 read_int64)
(define (print-int64 x)
(lambda (real-world)
(print_int64 (cons x real-world))))
(define (>> io1 io2)
(lambda (real-world)
(io2 (cdr (io1 real-world)))))
(define (>>= io f)
(lambda (real-world)
(let ((r (io real-world))
(v (car r))
(real-world2 (cdr r)))
(f v real-world2))))
(define (iomap io f)
(lambda (real-world)
(let ((r (io real-world))
(v (car r))
(real-world2 (cdr r)))
(cons (f v) real-world2))))
(define (fib n)
(let (((iter a b i)
(if (= i 0)
a
(iter b (+ a b) (- i 1)))))
(iter 0 1 n)))
(define main (>> (print-int64 1111111111)
(>>= (iomap read-int64 fib)
print-int64)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment