Last active
September 20, 2020 12:14
-
-
Save keigoi/7ab6c312028491e2ad54c1afce508255 to your computer and use it in GitHub Desktop.
Session Type Duality in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.function.Consumer; | |
import java.util.function.Function; | |
public class DualWork { | |
// セッション型 | |
public static class End{ | |
public End() {} | |
public void close() {} | |
} | |
public static class Send<CONT> { | |
public Send(Send<CONT> copy) {} | |
public CONT send() { return null; } | |
} | |
public static class Recv<CONT> { | |
public Recv(Recv<CONT> copy) {} | |
public CONT recv() { return null; } | |
} | |
public <S0, T0, S extends S0, T extends T0> Dual<S,T> RECUR(Dual <S0,T0> dual, Function<S0, S> f, Function<T0, T> g) { | |
return null; | |
} | |
// Duality の証拠 | |
public static abstract class Dual<S,T> { | |
public Dual(Dual<S,T> src) {} | |
public S startServer(Consumer<T> server) { | |
return null; | |
} | |
} | |
public static <S,T> Dual<Send<S>, Recv<T>> SEND(Dual<S,T> cont) { | |
return null; | |
} | |
public static <S1,T1> Dual<Recv<S1>, Send<T1>> RECV(Dual<S1,T1> cont) { | |
return null; | |
} | |
public static Dual<End, End> END() { | |
return null; | |
} | |
public class PingPong extends Send<Recv<PingPong>> { | |
public PingPong(Send<Recv<PingPong>> copy) { super(copy); } | |
} | |
public class PongPing extends Recv<Send<PongPing>> { | |
public PongPing(Recv<Send<PongPing>> copy) { super(copy); } | |
} | |
public class PINGPONG extends Dual<PingPong, PongPing> { | |
public PINGPONG() { | |
super(RECUR(SEND(RECV(new PINGPONG())), PingPong::new, PongPing::new)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment