News for hackers. Stuff that matters.
Re:Why I love Rust for tokenising and parsing by randomdata on Friday November 08, 2024 @04:04PM (#42090469)
> This is the sum type

This is the exact same thing, except in addition to the tag there is also a data component. Yes, this is the more traditional representation of sum types, but having an "undefined" data component is still identifiable as a sum type. It’s the tag in the union that makes it a sum type.

In Typescript terms, which I think illustrates this well, it is the difference between:

   { kind: 0 } | { kind: 1 }
and

   { kind: 0, data: T } | { kind: 1, data: U }
Which is to say that there is no difference with respect to the discussion here.

> They are an enumeration of discrete values

Yes, the "tag" is populated with an enumerator. There is an enumerator involved, but is outside of the type system. It's just an integer. The additional information you can gain from it, like exhaustive matching, comes at the type level.

Re:Why I love Rust for tokenising and parsing by samatman on Friday November 08, 2024 @07:40PM (#42091653)
There's absolutely a difference between an enumeration and a sum type.
Re:Why I love Rust for tokenising and parsing by randomdata on Saturday November 09, 2024 @08:52AM (#42094420)
Exactly. One describes a type, the other a numberer. Very different concepts, even if the latter is often used in the implementation of the former (e.g. in Pascal and Rust). Glad to see you are past your earlier confusion.
Re:Why I love Rust for tokenising and parsing by samatman on Saturday November 09, 2024 @11:30AM (#42095259)
You do not understand what a sum type is. At all.

There are innumerable ways you can rectify this lack of understanding if you want to.

Re:Why I love Rust for tokenising and parsing by randomdata on Sunday November 10, 2024 @10:04AM (#42100598)
There may be innumerable (ironic) ways for someone else to explain what it means, but we are here to understand what you mean. The only logical way to achieve that is for you to tell us.

1. If you have a pet sum type definition, let it be known. But traditionally, a sum type is better known as a discriminated or tagged union. So far, this is what we understand Pascal offers: A union type that discriminates its subtypes by an enumerated value.

2. The tag that discriminates the type within the union (or whatever your explanation above ends ups calling it) is, in implementation, generated by a process that assigns a number to each entity; something also true of Rust. This is undeniable, as proven by the use of Ord and mem::discriminant. If you have another name for that numberer, if not an enumerator, let it be known.