dedbox / racket-algebraic

Algebraic structures for untyped Racket
MIT License
75 stars 7 forks source link

add run-time polymorphism #67

Closed dedbox closed 5 years ago

dedbox commented 5 years ago

A class is a collection of potentially abstract variable bindings. Classes are useful as miniature interfaces for function groupings with interesting algebraic properties.

An instance is a first-class compile time value that implements the members of one or more classes.

(class Eq [== (.. not /=)] [/= (.. not ==)])
(define-syntax EqEq (instance Eq [== eq?]))
(with-instance EqEq (and (/= 'x 'y) (== 'a 'a)))

Instances can be combined.

(define-syntax BoxMonad
  (instance Monad extends (BoxApplicative BoxFunctor) ...))