Macaulay2 » Documentation
Packages » ForeignFunctions :: ForeignUnionType Thing
next | previous | forward | backward | up | index | toc

ForeignUnionType Thing -- cast a thing to a foreign union

Synopsis

Description

To cast a Macaulay2 thing to a foreign object with a union type, give the type followed by the thing. The appropriate member is determined automatically by foreignObject.

i1 : myunion = foreignUnionType("myunion", {"foo" => int, "bar" => double})

o1 = myunion

o1 : ForeignUnionType
i2 : myunion 27

o2 = HashTable{"bar" => 6.81224e-310}
               "foo" => 27

o2 : ForeignObject of type myunion
i3 : myunion pi

o3 = HashTable{"bar" => 3.14159   }
               "foo" => 1413754136

o3 : ForeignObject of type myunion

To avoid ambiguity, it may be helpful to first cast the thing to the appropriate foreign type.

i4 : myunion double 5

o4 = HashTable{"bar" => 5}
               "foo" => 0

o4 : ForeignObject of type myunion

Ways to use this method: