3 ms·
The advantage is you basically don't have to think about the provenance of data (in this example what state is a connection in? was it closed before being given
by almostdeadguy 8y ago
The advantage is you basically don't have to think about the provenance of data (in this example what state is a connection in? was it closed before being given to me? etc.). It allows the compiler to ensure the user of this code can't perform operations that lead to error states by allowing the programmer to express the state transitions of a connection in their function declarations, as the provided example shows:
newConnection :: Address -> Connection Closed
openConnection :: Connection Closed -> Connection Open
closeConnection :: Connection Open -> Connection Closed
connectionAddress :: Connection s -> Address
From a readability perspective, I would love this, it's effectively a state machine diagram explained by your function types.