Algebraic types and subclassing

Alan Grover awgrover@umich.edu
Tue, 10 Mar 1998 09:41:02 -0500


I'm wondering if I am being dense and just not thinking in the "Clean" way.
My other messages keep using this example. Does anyone have a suggestion on
the natural way to solve this problem in Clean?

There is a system type called OSType, which is a structure of exactly 4
bytes, often interpreted as a string of 4 characters.

The semantics almost match String. The exceptions are that the length is
always 4, and the characters can have any numeric value of 0 to 255. In
particular, it is convenient to use the String semantics to build, compare,
etc.

Since OSTypes are often embedded in other structures (resources, for
example), the i/o functions should be specialized so that they read/write
only the 4 bytes (no length, end mark, or translation). Also, for purposes
of passing values to the system API, the four bytes should be passed as an
immediate value (a long word).

Clearly I can't distinguish between a String and a 4 character String by
type (maybe I could use guards?). So I can't overload functions.

I don't want to duplicate all the String functions.

I think this problem occurs for other types.

How would you deal with this?

---
"Alan Grover, Technical Pb" awgrover@umich.edu
+1 (743) 647-5778
Project Leader
Health Media Research Lab, Cancer Center
5D04 North Ingalls Building, Mail Stop 0471
300 North Ingalls
Ann Arbor, MI 48109-0471