The instance is defined as
instance MonadFix [] where
mfix f = case fix (f . head) of
[] -> []
(x:_) -> x : mfix (tail . f)
But I'm failing to grasp the intuitive meaning behind it with respect to the []
monad seen as non-deterministic computations. In mfix f
function f
must not be strict in its argument, so it can't examine the argument. And according to the definition it also can't use the argument anywhere in its output, otherwise at some point it'll hit fix (f . head)
and diverge. So is there any use (or good example) for mfix
for lists, other than mfix (const someList)
?
f
must not be strict in its argument" doesn't mean that if can't examine the argument lazily. – Bangkok