There is a discussion about adding
, to fill floors and so on, and finally it says < / P>
User-defined types can easily participate in this type of enforcement system by defining methods of conversion of other types, and can provide some types of promotional rules that are available with other types of How to Promote them when mixed Should interest.
From this I have guessed that when my own numerical type is defined, I need to define it to work with functions on it How to change in the known type. But I tried it and it does not seem to work:
julia & gt; Type MyType n :: Int end julia & gt; Convert (Type: {IIT}, X :: MyType) = XN Convert (with Generic Function1 method) Julia & gt; Convert (Int, MyType (1)) 1 Julia & gt; MyType (1) + 1 error: There is no method matching in `+` (+ MyType, :: Int64)
+ >
+
to boost subtypes of +
: - ;
- In addition to the conversion function, you need to define a promotional rule.
What you should do the following:
Module Test Import Base: Convert, Protection_URL type MyType & lt;: number n :: In & Convert ( :: Type {at}, X :: MyType) = xn promotion_rule (typing {MyType}, :: Type {Int}) = Int end
Comments
Post a Comment