In this blog post, Tekmo makes the point that we can prove that ExitSuccess
exits because (I presume) it\'s like the Const
functor for
The answer is no, you cannot prove that the operational one ignores the rest of the program on exitSuccess
. Contrast TeletypeI
with TeletypeF
to see why. I'll rewrite TeletypeF
in GADT notation for easier comparison
data TeletypeF x where | data TeletypeI x where
PutStrLn :: String -> x -> TeletypeF x | PutStrLn :: String -> TeletypeI ()
GetLine :: (String -> x) -> TeletypeF x | GetLine :: TeletypeI String
ExitSuccess :: TeletypeF x | ExitSuccess :: TeletypeI ()
Using TeletypeF
, we can build actual programs right away:
GetLine (\str -> PutStrLn (map toUpper str) ExitSuccess)
TeletypeI
does not come with a way to refer to "the rest of the program" in the same way that TeletypeF
does.
-- TeletypeF:
GetLine (\str -> "rest of program" goes here)
-- or
PutStrLn someString ("rest of program" goes here)
-- or
ExitSuccess -- there is no "rest of program" slot provided
Since TeletypeI
lacks this "rest of the program" information, you can no longer gain any knowledge when you come across ExitSuccess
.
-- TeletypeI
PutStrLn someString -- no information about "rest of program"
-- or
GetLine -- no information about "rest of program"
-- or
ExitSuccess -- no information about "rest of program"
What is permissible to come as the "rest of the program" is entirely up to the Program
type, which doesn't know anything about the instruction set it is being applied to. It simply allows you to bind instructions together, and terminate via Return
.