Indeed I tried to do this "Yeti-side only", but unfortunately I'm a beginner in this and couldn't wrap my head around how to do that this way here.
So, to be more specific: I want to write custom Android layout; i.e., I'm writing a Yeti class "MyLayout" extending android.view.ViewGroup [1].
Now, from what I understand, in Android, layout classes are usually accompanied by corresponding "LayoutParams" -- for that I'm building a class MyLayoutParams, which has to be extending ViewGroup$LayoutParams. Those can be then passed into MyLayout's ViewGroup#addChild(view,layoutParams) [2], as a means to store per-child constraints for guiding the particular layout. Then, when resolving the layout geometry dynamically, in MyLayout#onMeasure(), for each child (added via addView()) I can call: this#getChildAt(i)#getLayoutParams() [3][4], which gives me a ViewGroup$LayoutParams reference, which is in fact instanceof MyLayoutParams...
[1]:
http://developer.android.com/reference/android/view/ViewGroup.html
[2]:
http://developer.android.com/reference/android/view/ViewGroup.html#addView%28android.view.View,%20android.view.ViewGroup.LayoutParams%29 [3]:
http://developer.android.com/reference/android/view/ViewGroup.html#getChildAt%28int%29 [4]:
http://developer.android.com/reference/android/view/View.html#getLayoutParams%28%29So, back to Yeti and tagged types: in MyLayoutParams (which must extend android.view.ViewGroup$LayoutParams), I want to store some tagged value (let's say, "Big () | Small () | Fixed number"). Then, later, I want to be able to nicely retrieve the tagged value when inside MyLayout#onMeasure(), and the input I have for this is the MyLayoutParams object I was able to get from: this#getChildAt(i)#getLayoutParams().
And this is the point, where I don't know how to do this Yeti-friendly?
After what you said, I'm starting to think whether I could get rid of the whole addView(...,...) and getChildAt(...) channel, but I'm afraid that Android could frown upon me (or otherwise explode when I least expect it) in such situation. I'd like to try being a Good Citizen as much as I can...
On the other hand, in the meantime I seem to have kinda resolved my original casting problem:
> {tto, tfrom} = (typedef tagged = A number | B number; tto x is tagged -> ~Object = x as ~Object; tfrom o is ~Object -> tagged = o unsafely_as tagged; {tto, tfrom})
tto is A. number | B. number -> ~java.lang.Object = <code$tto>
tfrom is ~java.lang.Object -> A number | B number = <code$tfrom>
with the caveat, that although seems much prettier than original "UnknownTag ()" approach, I'd surely much prefer some solution "fully in Yeti" and not having to force stuff unsafely through ~Object. Only I still can't invent it, unfortunately.
(As a side note, for now I want to build the final Anrdoid layout "programmatically", i.e. instantiating classes by hand in Yeti, instead of via XML resource files. I prefer Yeti to both Java and XML here.)
Not sure if any of this makes sense to you, sorry, I'm just starting to learn Android, so I'm not very knowledgeable in it, and it still feels quite complicated to me.
Thanks,
/M.