Implementing typestate

Tobias Müller via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 15 13:31:44 PDT 2015


Ola Fosheim Grøstad <ola.fosheim.grostad+dlang at gmail.com> wrote:
> On Tuesday, 15 September 2015 at 20:01:16 UTC, Meta wrote:
>> [...]
>> If I remember correctly Rust *did* have a typestate system very > early
>> on but it was done away with in favour of the borrow > checker.
> 
> Yeah, I've seen the Rust creator write about how they started out with
> all whistles and bells with the intent of having a full blow effect
> system. Then realized that they had to make things simpler and focus on
> memory management because that was the most critical feature. Probably a
> wise strategy to go for simplicity and hit version 1.0 sooner.

I think they settled for a simpler library solution using a marker type (I
think it was called Phantom type) as template parameter and then using
local shadowing to emulate mutable type state. Multiple variables with same
name but different (marker) type.
There's a Blog post somewhere but I can't find it atm.

Maybe that's also possible for D?

Tobi


More information about the Digitalmars-d mailing list