Skip to content

Instantly share code, notes, and snippets.

@Nymphium Nymphium/eff.rkt
Created Sep 3, 2018

What would you like to do?
#lang racket
(provide (except-out (all-defined-out) with-free Pure Free))
(require racket/control)
(struct Pure (r) #:transparent)
(struct Free (a k) #:transparent)
; (: compose [All (a b c) (-> (-> a b) (-> b c) (-> c d))])
(define (compose f g) (λ (x) (g (f x))))
(define (with-free f ph fh)
(match f
[(Pure r) (ph r)]
[(Free a k) ((fh a) k)]))
(define (newi)
(define-syntax define-effect
(syntax-rules ()
((_ name) (define name (newi)))))
(define ((invole p) e)
(shift-at p k (Free e k)))
(define ((((handler p) valh) oph) th)
[(h (λ (freer)
(λ (r) (valh r))
(λ (v) (λ (k) (oph v (compose k h)))))))
(freer (reset-at p (Pure (th))))]
(h freer)))
(define ((handle h) e) (h e))
(define (test)
(define-effect read)
(define (((readerh p) th) v)
(((((handler p)
(lambda (v) (lambda (_) v) ))
(lambda (x k) (lambda (s) ((k (+ x s)) s))))
th) v))
(define (hr p)
((readerh p)
(λ ()
(let* [(x ((invole p) 1))
(y ((invole p) (+ x 1)))]
((hr read) 10))

This comment has been minimized.

Copy link
Owner Author

Nymphium commented Sep 8, 2019

This is the implementation of 『Eff directly in OCaml』.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.