More documentation

This commit is contained in:
William J. Bowman 2015-11-10 18:24:38 -05:00
parent a57a719fdf
commit 27931803b0
No known key found for this signature in database
GPG Key ID: DDD48D26958F0D1A
4 changed files with 71 additions and 0 deletions

View File

@ -11,3 +11,5 @@ Cur has a small standard library, primary for demonstration purposes.
@include-section{stdlib/sugar.scrbl}
@include-section{stdlib/bool.scrbl}
@include-section{stdlib/nat.scrbl}
@include-section{stdlib/maybe.scrbl}
@include-section{stdlib/typeclass.scrbl}

View File

@ -0,0 +1,26 @@
#lang scribble/manual
@(require
"../defs.rkt"
scribble/eval)
@(define curnel-eval (curnel-sandbox "(require cur/stdlib/bool cur/stdlib/maybe cur/stdlib/sugar)"))
@title{Maybe}
@defmodule[cur/stdlib/maybe]
This library defines the datatype @racket[Maybe] and several forms for using them.
@; TODO: Define a @defdata macro for Cur
@deftogether[(@defthing[Maybe (∀ (A : Type) Type)]
@defthing[none (∀ (A : Type) (Maybe A))]
@defthing[some (∀ (A : Type) (a : A) (Maybe A))])]{
The maybe datatype.
}
@defform[(some/i a)]{
A syntactic form for @racket[some] that attempts to infer the type of the expression @racket[a] to reduce annotation burden.
@examples[#:eval curnel-eval
(some Bool true)
(some/i true)]
}

View File

@ -0,0 +1,42 @@
#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)]
}

View File

@ -7,6 +7,7 @@
racket/syntax
racket/dict
racket/list))
(provide (for-syntax typeclasses) typeclass impl)
;;; NB: This module is extremely unhygienic.
#| TODO: