4 ms·
The 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.
by calambrac 18y ago
The 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.