{"size": 1405, "ext": "scrbl", "max_stars_repo_path": "cur-doc/cur/scribblings/stdlib/typeclass.scrbl", "max_stars_repo_name": "jsmaniac/cur", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cur-doc/cur/scribblings/stdlib/typeclass.scrbl", "max_issues_repo_name": "jsmaniac/cur", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cur-doc/cur/scribblings/stdlib/typeclass.scrbl", "max_forks_repo_name": "jsmaniac/cur", "max_forks_repo_forks_event_min_datetime": "2021-10-02T16:05:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-02T16:05:54.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 32.6744186047, "max_line_length": 119, "alphanum_fraction": 0.6676156584}
#lang scribble/manual

@(require
  "../defs.rkt"
  scribble/eval)

@(define curnel-eval (curnel-sandbox "(require cur/stdlib/typeclass cur/stdlib/bool cur/stdlib/nat cur/stdlib/sugar)"))

@title{Typeclass}
@defmodule[cur/stdlib/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.

@defform[(typeclass (class (param : Type)) (name : t) ...)]{
Declares a new typeclass named @racket[class], whose parameter
@racket[param] has type @racket[Type]. Implementations of this
typeclass must define of the methods @racket[name ...] whose types
are @racket[t ...].

@examples[#:eval curnel-eval
          (typeclass (Eqv (A : Type))
	    (equal? : (forall (a : A) (b : A) Bool)))]
}

@defform[(impl (class param) defs ...)]{
Provides an implementation of the typeclass @racket[class] for the
type @racket[param]. The defintions @racket[defs ...] are Cur
definitions for each of the methods of the typeclass.

@examples[#:eval curnel-eval
          (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)
	  (equal? z z)]
}
