Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The first draft of new coercion semantics
This is a research work inspired by #1285. The following changes are included: - Coerions are made first-class type objects. It's now possible to pass a coercion around normally. Non-instantiable though akin to definites and subsets. - A parameter is now marked as `coercive` if its type is a coerce. - Coercions redelegate method calls to their target type. - Coercions type checks almost as they should. This is a temporary situation. Yet, `Str ~~ Int(Str)` is `True`, and 'Rat ~~ Int(Str)` is `False`. - Coercions are nominalizable. Nominalize into the target type. Aside of these, coercion protocol is introduced. If `coerce` method of `Metamodel::CoercionHOW` is used for `Foo(Bar)` then the following methods are tried in the order of mentioning: - the current standard of `Bar.Foo` - `Bar.COERCE-INTO(Foo)` - `Foo.COERCE-FROM(Bar)` Considering the discussion in Raku/problem-solving#137, the last one is the fallback of despair because, as was mentioned in the ticket, `Foo` might not have full information about `Bar` state and thus may not result in proper coercion. But the approach is safe to use for coercing from simple type objects. And in any case I think it is better to have something than have nothing and be forced to use augmentation. In either case, the use of `COERCE-*` methods allows to handle types with compound names without the risk of name clashes if short names of two or more type objects match.
- Loading branch information
Showing
5 changed files
with
223 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters