I am trying to do some work with phantom types and am struggling to really understand how to think. Given I have something like:
Session state := [Session {stream: Str}]
Offline : [Offline]
Online : [Online]
new_session : Username, Password -> Session Offline
new_session = |_, _| Session({stream: "test"})
connect!: Session Offline => Session Online
Now new_session will not type check, I need to also include the Offline but there is no way to do this. I must be missing some fundamental mental model about this. How would you impl new_session and connect! here to make it type check?
This works :)
Session line := {stream: Str}
Offline : [Offline]
Online : [Online]
new_session : Username, Password -> Session Offline
new_session = |_, _| @Session {stream: "test"}
connect!: Session Offline => Session Online
Username : Str
Password : Str
Last updated: Jul 05 2025 at 12:14 UTC