Cur
3.1 Datum
3.2 Sugar
3.3 Bool
3.4 Nat
3.6 Maybe
3.7 List
3.8 Equality
3.9 ASCII
3.11 Typeclass
On this page:
9.0
top
up

3.11TypeclassπŸ”— i

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 (classparam)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 (EqvBool )
(define(equal?(a:Bool )(b:Bool ))
(if a
(if bfalse true ))))
> (impl (EqvNat )
(defineequal?nat-equal? ))
> (equal?true true )

(true)

> (equal?z z )

(true)

top
up

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /