On this page:
typeclass
impl
7.1

3.11 Typeclass

This library defines some macros that provide ad-hoc polymorphism similar to typeclasses, although lacking some of the crucial features of typeclasses such as typeclass constraints. These typeclasses are added entirely through meta-programming.

syntax

(typeclass (class (param : Type)) (name : t) ...)

Declares a new typeclass named class, whose parameter param has type Type. Implementations of this typeclass must define of the methods name ... whose types are t ....

Example:
> (typeclass (Eqv (A : Type))
  (equal? : (-> (a : A) (b : A) Bool)))

syntax

(impl (class param) defs ...)

Provides an implementation of the typeclass class for the type param. The defintions defs ... are Cur definitions for each of the methods of the typeclass.

Examples:
> (impl (Eqv Bool)
    (define (equal? (a : Bool) (b : Bool))
      (if a
          (if b true false)
          (if b false true))))
> (impl (Eqv Nat)
    (define equal? nat-equal?))
> (equal? true true)

(true)

> (equal? z z)

(true)