I want to write a slick bit of code (saving me much time to implement otherwise) by tying the knot. It goes roughly like this,
n <- myinstr n x
where in theory, myinstr
should run x
to get a value, which will become n
. myinstr
, which runs inside a State
monad, will put n
into the state, but this doesn't affect x
's computation.
I've tried using DoRec
and a naiive implementation of mfix
,
instance Monad πͺ => MonadFix (MyMonad πͺ) where
mfix f = fix (\mx -> mx >>= f)
but things freeze. Are there any methods for fixing my code (or methodologies for designing it correctly the first time) or should I write something more straightforward?