Proofs
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 that constructor (it doesn't carry the x
so fmap
behaves like const
).
With the operational package, Tekmo's TeletypeF
might be translated something like this:
data TeletypeI a where
PutStrLn :: String -> TeletypeI ()
GetLine :: TeletypeI String
ExitSuccess :: TeletypeI ()
I've read that operational is isomorphic to a free monad, but can we prove here that ExitSuccess
exits? It seems to me that it suffers from exactly the same problem as exitSuccess :: IO ()
does, and in particular if we were to write an interpreter for it, we'd need to write it like as if it didn't exit:
eval (ExitSuccess :>>= _) = exitSuccess
Compare to the free monad version which doesn't involve any pattern wildcard:
run (Free ExitSuccess) = exitSuccess
Laziness
In the Operational Monad Tutorial apfelmus mentions a drawback:
The state monad represented as s -> (a,s) can cope with some infinite programs like
evalState (sequence . repeat . state $ \s -> (s,s+1)) 0
whereas the list of instructions approach has no hope of ever handling that, since only the very last Return instruction can return values.
Is this true for free monads as well?
Free (Coyoneda f)
,Coyoneda f
is isomorphic tof
, soFree (Coyoneda f)
is isomorphic toFree f
. – Edward KmettCoyoneda Const a ~= Identity a
, which is not isomorphic toConst a
. – Heinrich ApfelmusCoyoneda (Const m) a
is isomorphic toConst m a
which is isomorphic tom
. – Edward Kmettdata Foo a = Foo
functor thenCoyoneda Foo a = exists b. (b -> a, Foo)
which doesn't give you an extra element, since you don't have ab
to call the function with. – Edward Kmett