Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

非継続渡しの消極的選択メソッド #7

Open
curegit opened this issue May 9, 2019 · 1 comment
Open

非継続渡しの消極的選択メソッド #7

curegit opened this issue May 9, 2019 · 1 comment

Comments

@curegit
Copy link
Owner

curegit commented May 9, 2019

非継続渡しの消極的選択メソッドを実装したい。

分岐先を表すコンストラクタと分岐先のセッションをもつバリアントを用意するのが理想。

Choice <a, b> = Left of a | Right of b

コンスタントをinternalにした抽象クラスを用いると、派生クラスの作成を制限できる。
バリアントの代わりとなる。

namespace SessionTypes.Binary
{
	public abstract class Choice<L, R> where L : SessionType where R : SessionType
	{
		internal Choice() { }
	}

	public sealed class Left<L, R> : Choice<L, R> where L : SessionType where R : SessionType
	{
	}

	public sealed class Right<L, R> : Choice<L, R> where L : SessionType where R : SessionType
	{
	}
}

しかしダウンキャストのために型をパラメータ含めて書く必要がある。

switch (c2.Follow())
{
	case Left<Respond<int, Close>, Respond<string, Close>> left:
		break;
	case Right<Respond<int, Close>, Respond<string, Close>> right:
		break;
}

非継続渡しの消極的選択メソッドとFluent APIをあわせると、名前変えを抑えつつ手続き的な制御構造と親和に書けるので、需要は大きい。
もっと思考を要する。

@curegit
Copy link
Owner Author

curegit commented Dec 2, 2019

Type patterns と Discriminated Union が導入された場合、ダウンキャストで綺麗に分岐が書けると予想

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant