|
hace 4 meses | |
---|---|---|
LICENSE | hace 4 meses | |
README.md | hace 4 meses | |
release-info | hace 4 meses | |
trait.egg | hace 4 meses | |
trait.scm | hace 4 meses |
A trait/typeclass system for Scheme.
(import trait)
(define-record point x y)
(define-trait Eq
;; fallback to equal? by default
(same? equal?))
(define-trait-impl (Eq number?)
(same? =))
(define-trait-impl (Eq symbol?)
(same? eq?))
(define-trait-impl (Eq point?)
(same? (lambda (a b) (and (point? b)
(= (point-x a) (point-x b))
(= (point-y a) (point-y b))))))
(display (list (same? 'a 'a)
(same? 1 1)
(same? 1 2)
(same? (list 1 2) (list 1 2))
(same? (cons 3 4) (cons 3 4))
(same? (make-point 1 2) (make-point 3 4))))