3 ms·
>>If trees are made us using Leaf, Node, and Empty, tree "leaks" names, which is a disaster because lots of things have leaves, nodes, and empty.' >Non sequitu
by anamax 18y ago
>>If trees are made us using Leaf, Node, and Empty, tree "leaks" names, which is a disaster because lots of things have leaves, nodes, and empty.'
>Non sequitur? Where is the problem. Try
> data MyMaybe a = Just a | Nothing
Huh? How does that create a tree instead of a banana?
Actually, it's completely unclear what that example is doing. I'd guess that it's specifying a new name and a corresponding value, but I'm not sure which name and what kind of value.
- calambrac 18y agoThe Just and Nothing that he's defining for his MyMaybe are completely different things from the Just and Nothing used for the Maybe that ships in the Prelude. MyMaybe may as well be a banana for all Prelude.Maybe cares.
- eru 18y agoYes. And my code does 'nothing'. It just defines an algebraic datatype.
- anamax 18y agoI know why I might want to define a tree. I have no idea why I want to define an algebraic datatype. Note "you can define trees using algebraic datatypes" doesn't tell me why I want to use algebraic datatypes.
- calambrac 18y agoI want to use them so I don't have to write very much code, so that I can easily reason about my program by directly substituting symbols with their definitions, so that I can use pattern matching against instances of that type, so that I can group them into type classes and know what operations I'll have available to work with them... etc.
- eru 18y agoI thought trees where algebraic datatypes?
- JulianMorrison 18y agoIt's more or less the haskell version of a struct or a public class with fields and no methods, except that you can specify more than one shape for the same type. data MyMaybe a = Just a | Nothing ...means in Java speak "MyMaybe<a> is an abstract generic superclass with a final singleton subclass Nothing<a> having no fields, and a final subclass Just<a> having one field of type a" You then write functions that take that data and use it.