3 ms·
So basically Clojure protocols? As in, multimethods that dispatch on the type of their first argument?
by idontpost 8y ago
So basically Clojure protocols? As in, multimethods that dispatch on the type of their first argument?
- joshuamorton 8y agoExcept that assuming Animal is a sum type (kind of like an enum), the computer will complain. So a maybe type (equivalent to an Optional) is simply a sum over just and nothing (the two components). If you fall to handle nothing, the program won't compile. Animal would work the same way. Add "Cow" as an animal, and your program won't compile until everything sanely handles Cow. So more like a switch case over a set of options where the compiler prevents you from forgetting any.