News for hackers. Stuff that matters.
Re:How Rust Gets Polymorphism Right [video] by mathw on Monday November 13, 2017 @03:20AM (#15685065)
Yes I always thought tuples were the archetypal product type, which is why in some ML dialects they're notated as "Type1 * Type2".

Rust most certainly has them, as does Haskell. Records/structs of course are just the same thing with names for the components.

Thus, even Java has product types.

Re:How Rust Gets Polymorphism Right [video] by masklinn on Monday November 13, 2017 @03:44AM (#15685166)
> Thus, even Java has product types.

Even C has product types. Which is why I'm always bothered when people claim language X lacks algebraic data types.

They probably lack sum types, but are very unlikely to lack product types.

Re:How Rust Gets Polymorphism Right [video] by kod on Monday November 13, 2017 @08:26AM (#15686355)
Product types without sum types and pattern matching are basically useless for expressing ADTs. That's what people mean.
Re:How Rust Gets Polymorphism Right [video] by masklinn on Monday November 13, 2017 @08:31AM (#15686382)
> Product types without sum types and pattern matching are basically useless for expressing ADTs.

That makes no sense. Algebraic data types are not expressed, they're a concrete thing, a classification of composite types (by multiplication (hence product types) or addition (hence sum types)).

Re:How Rust Gets Polymorphism Right [video] by kod on Monday November 13, 2017 @01:56PM (#15689026)
Sure it does, languages allow you to express things.

Some shitty languages don't have a concise way for you to express particular things (like sum types), so you have to rely on idioms or "patterns".

Re:How Rust Gets Polymorphism Right [video] by beojan on Monday November 13, 2017 @05:45AM (#15685557)
C also has sum types with unions (though without any indication of which of the alternatives is actually present).
Re:How Rust Gets Polymorphism Right [video] by red75prime on Monday November 13, 2017 @06:43AM (#15685779)
They are mix types then.
Re:How Rust Gets Polymorphism Right [video] by bjz_ on Monday November 13, 2017 @07:44AM (#15686055)
And in SML tuples are just records with numeric fields in a special order. Enter this in the repl:

    { 1 = "hi", 2 = "howdy" };
And get:

    val it = ("hi","howdy") : string * string
Re:How Rust Gets Polymorphism Right [video] by kornish on Monday November 13, 2017 @03:44AM (#15685168)
Oh wow, never realized the connection between product types and the ML type notation. Thanks for the insight!
Re:How Rust Gets Polymorphism Right [video] by jmcomets on Monday November 13, 2017 @04:09AM (#15685254)
Thanks for the insight on this, I've edited my response. Are there any extra features in Haskell with product types? I've always understood that there was better composition support for product types in Haskell
Re:How Rust Gets Polymorphism Right [video] by bjz_ on Monday November 13, 2017 @09:15AM (#15686638)
Not really. Haskell has support for higher kinded types that allow it to support lenses, which are a powerful way of declaratively traversing through data structures, so perhaps that's what you mean. On the other hand Haskell's record support is pretty woeful in comparison to languages like Ocaml, Elm, and Purescript that have support for row polymorphism. Depending on the sophistication of their implementation, row polymorphism will allow you to add and remove fields from records in a statically type checked way, and some may even allow you to pass labels around at the type level. They can even be used to model extensible variants and extensible effect types. There are creative ways to encode this in Haskell, but they all have their drawbacks, can be painful to work with, and really don't feel like a natural part of the language.
Re:How Rust Gets Polymorphism Right [video] by kazagistar on Monday November 13, 2017 @11:05AM (#15687417)
Well, there is per-field lazyness (with the ability to opt out). So product types can let each consumer choose which parts of the result to actually evaluate and discard the rest.