Duck Typing / Row Typing in LSTS
Duck-typing is a feature in several languages that implements the idea “if it looks like a duck, and it quacks like a duck, then treat it like a duck.” In functional language this feature is often called “row typing.” The core idea is to work with objects and classes based on their shape rather than their name.
Row Typing in LSTS
When destructuring an object in LSTS, normally the programmer will add a case tag to indicate what type case is intended to be used. If the programmer replaces this case tag with an underscore, then the compiler knows that the programmer intends to use only row-typing to destructure the object.
A normal object might be destructured like this.
match object {
ObjectCase { field-1=field-1 } => print(field-1);
}In row typing the programmer can ignore the case.
match object {
_ { field-1=field-1 } => print(field-1);
}Caveats to Row Typing
When destructuring with row typing, it is important to understand that the compiler may not be able to infer the case of the object. This means that row typing can only be used with objects with a single case or with fields that are synthesized.
Duck typing may be familiar to programmers who are more familiar with dynamic languages. There are a large number of interesting algorithms and design patterns that are made possible through this feature.


