[rust-dev] Bring Back Type State

Eric Reed ecreed at cs.washington.edu
Wed Jun 4 23:03:57 PDT 2014


I'm not going to claim canonicity, but I used the type system to encode the
socket state machine (see std::io::net::{tcp,udp}).
TcpListener consumes itself when you start listening and becomes a
TcpAcceptor.
UdpSocket can "connect" (i.e. ignore messages from other sources) and
become a UdpStream, which can "disconnect" (i.e. stop ignoring) and become
a UdpSocket again.

It's actually very easy to do. Make every state a distinct affine type.
Implement state transitions as methods that take self by value (consume old
state) and return the new state.


On Wed, Jun 4, 2014 at 10:40 PM, Cameron Zwarich <zwarich at mozilla.com>
wrote:

> Is there a canonical example of encoding a state machine into Rust's
> substructural types?
>
> Cameron
>
> On Jun 4, 2014, at 10:14 PM, Brian Anderson <banderson at mozilla.com> wrote:
>
> Thank you for your suggestion, but typestate is not coming back. There is
> no room in the complexity budget for another major piece of type system,
> and linear types can serve much the same purpose.
>
> On 06/04/2014 10:11 PM, Suminda Dharmasena wrote:
>
>  Hi,
>
>  The initial Type State implementation in Rust was not a great way to get
> about it. Please reconsider adding type state like it has been done in the
> Plaid language.
>
>  Basically you can use traits mechanism to mixin and remove the trait
> when methods marked as having state transitions.
>
>  Suminda
>
>  Plaid: http://www.cs.cmu.edu/~aldrich/plaid/
>
>
> _______________________________________________
> Rust-dev mailing listRust-dev at mozilla.orghttps://mail.mozilla.org/listinfo/rust-dev
>
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140604/60f8bb02/attachment.html>


More information about the Rust-dev mailing list