Hacker News new | past | comments | ask | show | jobs | submit login

I would probably do it like this in D (disclaimer: I haven't tested this code!)

  import std.typecons;
  import std.socket;
  import std.variant;

  struct Disconnected {}
  struct Connecting {}

  alias Connected = Typedef!(TcpSocket, null, "connected");
  alias Transferring = Typedef!(TcpSocket, null, "transferring");

  alias ConnState = Algebraic!(Disconnected, Connecting, Connected, Transferring);
You could use plain structs instead of the typedef template for the same result.



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: