1. In node, the msg parameter is for the types of messages the node can emit. So if you have a text-box that emits messages when its value changes, it could have type "Node String".
2. The "type Node msg = Node" is really just some hackery to get things working with Native. It's just declaring to Elm that there is a type called Node with a parameter msg. The right hand side is just there because something has to be there: it's declaring a constructor "Node" which takes no arguments, but this never gets used, since actual Node values are produced in Native code. 3. The type "String -> Json.Value -> Property msg" means that, if you give this function a string and a Json.Value, it will give you a value that can typecheck against any type of "msg" it needs to. Basically, this means that the function doesn't actually do anything with the type parameter, so it will work for any type you give it. This lets you use it in any context you need. Native is really quite hackish: it's literally just making the calls to the given JavaScript, and is completely unchecked, which is why it's intended for Elm's internal use only. Nothing too fancy is going on, it's just doing what's necessary to please the Elm type-checker, while injecting JS code. On Wed, Feb 15, 2017 at 10:31 AM, Will Tian <[email protected]> wrote: > Hi, > > I'm trying to understand how the Html module works. I see many methods > with return type Html msg, which is a type alias for Node msg. > > After tracking down the source code and reading into it, I am confused by > the following line: > > type Node msg = Node > > what is the purpose of the above line? > > Furthermore, I don't understand the use of the type parameter msg. > > For example I can see that type Property msg = Property > > and > > property : String -> Json.Value -> Property msg > property = Native.VirtualDom.property > > when looking into the implementation of VirtualDom.property, I see > > function property(key, value) > { > return { > key: key, > value: value > }; > } > > Does that mean the return value of calling: property "className" > (Json.string "myClass") is of type Property msg where msg = { key: > "className", value: "myClass" }? > does the property function actually use a type constructor and return the > type? > > Thanks in advance. > > > -- > You received this message because you are subscribed to the Google Groups > "Elm Discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
