srfi.137
- Minimal unique types ¶This SRFI provides a simple way to create disjoint types. It’s so simple that it’s easy to write a portable implementation. It can also be a basis of libraries that requires objects with their own distinct types.
The system is minimal, both in a way that it can be implemented on the very basic features of Scheme, and in a way that it provides a single API. If you’re writing Gauche code, or even portable R7RS, you may choose fancier abstraction utilities such as Gauche classes or R7RS records. This SRFI is useful for code that can only assume rudimental Scheme implementation, and this module comes handy when you want to run such code in Gauche.
(In Gauche, this module is implemented on top of Gauche’s object system.)
[SRFI-137]{srfi.137
}
Returns 5 procedures. They collectively define a conceptual unique type.
Returns type-payload.
Returns a newly allocated instance of this type, holding instance-payload in it. The returned object is of a type disjoint to any other existing types.
Returns #t
if obj is an object created by constructor.
Returns instance-payload of instance. The argument must be an object created by constructor.
Returns 5 procedures, associated to a newly created type which is subtype of the originaltype.
In our implementation, make-type
creates a fresh new class,
and constructor creats an instance of the class.
The SRFI does not provide the means to access the underlying class,
but in Gauche you can use class-of
on the instance to obtain it.
(Of course, messing with the underlying class is inherently unportable.)