On 7 September 2015 at 15:49, Timothy Baldridge <tbaldri...@gmail.com> wrote: > > Types are good even in dynamic languages, we should use the more. As > mentioned by Thomas, records are the idiomatic way to store typed > information in Clojure. >
I don't think that's true. Or rather, I think it depends on what you mean by "type". In core.typed parlance, a "type" is a means of validating the shape of data at compile time. We can use a vector to represent a variant, and still have it typed: (defalias FooResult (U '[(Value :ok) Int] '[(Value :err) Str])) Dynamic typing libraries like Schema or Annotate have a similar notion of types, but perform their checks at runtime. In both cases, the type is independent of the data; we can determine whether a data structure matches a specific type, but the type isn't tied to the data. In contrast, we have a notion of what core.typed and edn calls a "tag", which is attached directly to the data structure. A record is essentially a tagged map, and if we didn't have to worry about performance, tags would probably just be implemented as metadata. If we're talking about records, then we're talking about tags more than types, and the question becomes: what data should we tag? If we want runtime polymorphism, then it makes sense to use a tag so we have something to dispatch off. But is there any other practical reason we'd want to use a tagged structure in Clojure? I'm not convinced there is. Records are useful for polymorphism, and perhaps performance if that level of optimisation is necessary, but I don't see any other benefit. > The above video is a exploratory explanation of a different way of > thinking of data, but I have never seen code like that in production, and > it's so different from idiomatic Clojure, that I would be hesitant to adopt > it wholesale. > A lot of people use Instaparse and Hiccup in production, which I believe the video explicitly mentions as being examples of variants. - James -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.