> <\body> User classes can be defined within , as shown in the following example: <\session|mathemagix|default> <\unfolded-io> <|unfolded-io> type_mode? := true <|unfolded-io> : <\input> <|input> class Color == { \ \ mutable { r: Double; g: Double; b: Double; } \ \ constructor grey (x: Double) == { \ \ \ \ r == x; g == x; b == x; } \ \ constructor rgb (r2: Double, g2: Double, b2: Double) == { \ \ \ \ r == r2; g == g2; b == b2; } } <\unfolded-io> <|unfolded-io> rgb (1, 0, 0) <|unfolded-io> >: <\input> <|input> flatten (c: Color): Syntactic == \ \ syntactic ('rgb (as_generic flatten c.r, \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ as_generic flatten c.g, \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ as_generic flatten c.b)); <\unfolded-io> <|unfolded-io> rgb (1, 0, 0) <|unfolded-io> >: <\input> <|input> mix (c1: Color, c2: Color, a: Double): Color == \ \ rgb (a * c1.r + (1-a) * c2.r, \ \ \ \ \ \ \ a * c1.g + (1-a) * c2.g, \ \ \ \ \ \ \ a * c1.b + (1-a) * c2.b); <\unfolded-io> <|unfolded-io> mix (rgb (1, 0, 0), grey (0.5), 0.5) <|unfolded-io> >: The operator > can be used to convert a given type into another, provided that the corresponding function is defined. We show here an example of an explicit conversion from a class to the class : <\session|mathemagix|default> <\input> <|input> class Alpha_color == { \ \ mutable { c: Color; a: Double; } \ \ constructor alpha_color (c2: Color, a2: Double) == { c == c2; a == a2; } }; <\unfolded-io> <|unfolded-io> alpha_color (rgb(0,0,1), 0.5) <|unfolded-io> ,0.5|]>,Alpha_color|)>>: <\input> <|input> downgrade (ac: Alpha_color): Color == mix (ac.c, rgb(1,1,1), ac.a); <\unfolded-io> <|unfolded-io> alpha_color (rgb(0,0,0), 0.6) :\ Color <|unfolded-io> >: In order to define implicit conversions from a type into another, one can use the function . We complete the example with a convert from to : <\session|mathemagix|default> <\input> <|input> upgrade (x: Double): Color == grey x; <\unfolded-io> <|unfolded-io> mix (1.0, rgb (0, 1, 0), 0.2) <|unfolded-io> >: <\unfolded-io> <|unfolded-io> mix (0.8, 0.2, 0.4) <|unfolded-io> >: <\input> <|input> postfix .greyed (c: Color): Color == (c.r + c.g + c.b) / 3; <\unfolded-io> <|unfolded-io> rgb (1, 0, 0).greyed <|unfolded-io> >: . If you don't have this file, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.>