source: project/wiki/eggref/4/type-extensions @ 36801

Last change on this file since 36801 was 36801, checked in by evhan, 11 months ago

wiki/eggref: update docs/formatting/urls and eggref/5/{r7rs,fancypants,chicken-belt}

File size: 1.6 KB
Line 
1[[tags: egg]]
2
3== type-extensions
4
5[[toc:]]
6
7== Description
8
9Miscellaneous extensions for CHICKEN's type system.
10
11The source for this egg is available
12[[https://git.foldling.org/chicken-type-extensions.git|here]].
13
14=== Requirements
15
16* [[matchable]]
17
18== Usage
19
20{{type-extensions}} should be loaded as a compiler extension with the
21{{-extend}} (or {{-X}}) flag to {{csc}}:
22
23    $ csc -extend type-extensions <file>
24
25=== API
26
27<syntax>(define-type name)</syntax>
28
29Shorthand for {{(define-type name (struct name))}}.
30
31<syntax>(define-type (name var ...) type)</syntax>
32
33Defines a complex type alias that can be used in place of {{type}}. In
34each usage, all instances of {{var}} in {{type}} will be replaced by the
35corresponding form from {{(name var ...)}}.
36
37<enscript highlight="scheme">
38(define-type (pair-of a) (pair a a))
39
40(: pair (forall (a) (a -> (pair-of a))))
41(define (pair x) (cons x x))
42
43(compiler-typecase (pair 1)
44  ((pair-of fixnum)
45   (print '(pair-of fixnum)))
46  (else
47   (print 'else)))
48</enscript>
49
50As with CHICKEN's built-in {{define-type}} form, type aliases defined
51inside a module are not visible outside of that module.
52
53=== Type Syntax
54
55<syntax>(list . type)</syntax>
56<syntax>(list type ...)</syntax>
57
58A dotted tail or ellipsis at the end of a {{list}} type form is
59shorthand for a sequence of pairs followed by {{(list-of type)}}.
60
61<enscript highlight="scheme">
62;; The following types are equivalent:
63(define-type a (list fixnum float . number))
64(define-type b (list fixnum float number ...))
65(define-type c (pair fixnum (pair float (list-of number))))
66</enscript>
67
68== Author
69
70[[/users/evan-hanson|Evan Hanson]]
71
72== License
73
743-Clause BSD
Note: See TracBrowser for help on using the repository browser.