defining a tuple data type of unknown length in Rascal -
I was curious to know that any data type that we know should be a tuple, But its length (or the number of elements is uncertain) is currently the application as follows:
// I want to declare a data type, which is a tuple public data, MyType = fromListCartesianProduct ( Tuple & lt ;? & gt; product) // later i get list-cartesian product I want to infiltrate myType data / some maitype data forward (instant [1,2,3] * ["a", "b"]) some arre [i] = fromListCartesianProduct (aTuple) The main observation is that the number of elements in the Atom is uncertain while declaring "MyType". Can I still declare a kind of written in a kind of fraud?
Alternatively, I will declare Mai type as such:
public data MyType = fromListCartesianProduct (list [] product) < P> And replace each carton product by listing the cartesian product before making specific examples. For clarity and for others reasons, I would like to define my type as I did before.
There is no answer in the precepts, the length of the tuples is fixed and we (nevertheless) are not row polymorphism.
By saying that the data constructors support a variety of polymorphs that may help:
-
By using the line polymorphism keyword parameter, you always More keyword criteria can be added in a data-type, such as
data MyType = myCons (int j = 0); // Initial announcement data MyType (Int k = 1); / />Overloaded, you can always add more constructors with more parameters
Data MyType = f (Int i); // Initial declaration data MyType = f (int i, int j); // Overloaded announcement with more fields
You can dynamically type type from the create function You can use such constructor based on the logic list at the risk of run-time type exceptions of the course.
Another way to deal with unexpected type of data is to go up one level in the type hierarchy (this is value ), and later patterns get their own path again:
list [value] myListRelationOfUnknownType = ...; Println ("print only joints of ints: ; - j & gt;"); (& lt; int i, int j & gt; & lt; - myListRelationOfUnknownType); Println ("only print triples of ints: <-> - & lt (& lt; int i, int j, int k & gt; & lt; - myListRelationOfUnknownType) ; K & gt; "); This is a statically more secure way.
Comments
Post a Comment