@chenyan I’m honestly a little confused by that syntax. What’s the #
there for? In the docs, I see some examples using that symbol to declare enums but not variables:
type Vec3D = { x : Float; y : Float; y : Float };
type Order = { #less; #equal; #more };
What does adding the #
do before a variable definition? What would happen if I was to add before to x
, y
, and y
above? (that last one should probably be z
, not y
…)
Why would you write your example as you did instead of:
type Node = {
element: [Node];
text: Text;
};
I think it has something to do with variant type fields, but I’m not even sure what that means. The docs don’t really explain it, they just start using #
in some places but not others.
Why is it better to have just a Node type instead of my two distinct types? Element nodes don’t have a Text field, and Text nodes don’t have any children. Shouldn’t those be different types? I think maybe I’ve never worked in a language with “full variant type”; I’m not sure what that means.
Lastly, why did you choose to use two type
definitions instead of two classes? Won’t I need a constructor for my objects?
Thanks for clearing some of this up for me as I try to wrap my head around this new language.