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

Last change on this file since 33385 was 33385, checked in by evhan, 3 years ago

egg-locations: Migrate my eggs from bitbucket.org to foldling.org

File size: 1.7 KB
RevLine 
[31521]1[[tags: egg]]
2
3== type-extensions
4
5[[toc:]]
6
7=== Description
8
[33385]9Miscellaneous extensions for CHICKEN's type system.
[31521]10
[33385]11The source for this egg is available
12[[http://git.foldling.org/chicken-type-extensions.git|here]].
[31522]13
[31521]14==== Requirements
15
16* [[/egg/matchable|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
[33385]27<syntax>(define-type name)</syntax>
28
29Shorthand for {{(define-type name (struct name))}}.
30
[31521]31<syntax>(define-type (name var ...) type)</syntax>
32
33Defines a complex type alias that can be used in place of {{type}}. In
[31522]34each usage, all instances of {{var}} in {{type}} will be replaced by the
35corresponding form from {{(name var ...)}}.
[31521]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
[31528]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
[31521]68=== Author
69
70[[/users/evan-hanson|Evan Hanson]]
71
72=== License
73
[31528]74Copyright (c) 2014, 3-Clause BSD.
Note: See TracBrowser for help on using the repository browser.