From 27931803b0f12206d5519c76fddd6a31b56d413b Mon Sep 17 00:00:00 2001 From: "William J. Bowman" Date: Tue, 10 Nov 2015 18:24:38 -0500 Subject: [PATCH] More documentation --- scribblings/stdlib.scrbl | 2 ++ scribblings/stdlib/maybe.scrbl | 26 ++++++++++++++++++ scribblings/stdlib/typeclass.scrbl | 42 ++++++++++++++++++++++++++++++ stdlib/typeclass.rkt | 1 + 4 files changed, 71 insertions(+) create mode 100644 scribblings/stdlib/maybe.scrbl create mode 100644 scribblings/stdlib/typeclass.scrbl diff --git a/scribblings/stdlib.scrbl b/scribblings/stdlib.scrbl index 4682c30..cb9a3a1 100644 --- a/scribblings/stdlib.scrbl +++ b/scribblings/stdlib.scrbl @@ -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} diff --git a/scribblings/stdlib/maybe.scrbl b/scribblings/stdlib/maybe.scrbl new file mode 100644 index 0000000..80b1f8a --- /dev/null +++ b/scribblings/stdlib/maybe.scrbl @@ -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)] +} diff --git a/scribblings/stdlib/typeclass.scrbl b/scribblings/stdlib/typeclass.scrbl new file mode 100644 index 0000000..db1826a --- /dev/null +++ b/scribblings/stdlib/typeclass.scrbl @@ -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)] +} diff --git a/stdlib/typeclass.rkt b/stdlib/typeclass.rkt index c4b95e9..bc41256 100644 --- a/stdlib/typeclass.rkt +++ b/stdlib/typeclass.rkt @@ -7,6 +7,7 @@ racket/syntax racket/dict racket/list)) +(provide (for-syntax typeclasses) typeclass impl) ;;; NB: This module is extremely unhygienic. #| TODO: