Is there any way to add my own annotations to values or functions in Mathematica? Imagine, for example, that I wanted to annotate a List
specifically as a List
of String
s.
I don't think Mathematica will really do anything to enforce such a thing, but what I'd like to use this for is for connecting Mathematica to .NET generic functions. If I know that a List
is expected to only contain a single type, I could more easily decide what type to call into a generic function with.
An example syntax might be something like:
mylist = {"Alice", "Bob", "Carol"}
SetAttribute[myList, NETType[String]]
(* The NETType[] attribute is used to call "GenericListMethod<String>(myList);" *)
NETGenericCall[GenericListMethod,Sequence[myList]]
Update: It's also significant that myList
should retain (nearly?) native behavior in Mathematica. For example, I should be able to iterate over the list with Map[] without having to explicitly unwrap the list first. I figure it's asking almost entirely too much for normal Mathematica functions to preserve type information.