Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Subtyping
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Coercions== In coercive subtyping systems, subtypes are defined by explicit [[type conversion]] functions from subtype to supertype. For each subtyping relationship (''S'' <: ''T''), a coercion function ''coerce'': ''S'' β ''T'' is provided, and any object ''s'' of type ''S'' is regarded as the object ''coerce''<sub>''S'' β ''T''</sub>(''s'') of type ''T''. A coercion function may be defined by composition: if ''S'' <: ''T'' and ''T'' <: ''U'' then ''s'' may be regarded as an object of type ''u'' under the compound coercion (''coerce''<sub>''T'' β ''U''</sub> β ''coerce''<sub>''S'' β ''T''</sub>). The [[type coercion]] from a type to itself ''coerce''<sub>''T'' β ''T''</sub> is the [[identity function]] ''id''<sub>T</sub>. Coercion functions for records and [[disjoint union]] subtypes may be defined componentwise; in the case of width-extended records, type coercion simply discards any components which are not defined in the supertype. The type coercion for function types may be given by ''f'''(''t'') = ''coerce''<sub>''S''<sub>2</sub> β ''T''<sub>2</sub></sub>(''f''(''coerce''<sub>''T''<sub>1</sub> β ''S''<sub>1</sub></sub>(''t''))), reflecting the [[Covariance and contravariance (computer science)|contravariance]] of parameter values and covariance of return values. The coercion function is uniquely determined given the subtype and [[supertype]]. Thus, when multiple subtyping relationships are defined, one must be careful to guarantee that all type coercions are coherent. For instance, if an integer such as 2 : ''int'' can be coerced to a floating point number (say, 2.0 : ''float''), then it is not admissible to coerce 2.1 : ''float'' to 2 : ''int'', because the compound coercion ''coerce''<sub>''float'' β ''float''</sub> given by ''coerce''<sub>''int'' β ''float''</sub> β ''coerce''<sub>''float'' β ''int''</sub> would then be distinct from the identity coercion ''id''<sub>''float''</sub>.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)