Proposal: Warn about ArrowLoop instance for Kleisli Arrows

Heinrich Apfelmus apfelmus at quantentunnel.de
Sun Oct 9 16:14:32 CEST 2011


Henning Thielemann wrote:
> On Sun, 9 Oct 2011, Heinrich Apfelmus wrote:
>> I recently noticed that the instance
>>
>>    MonadFix m => ArrowLoop (Kleisli m)
>>
>> does not fulfill the ArrowLoop laws for most monads, rendering it either
>> useless or dangerous for the unwary. Removing it would be the correct
>> thing to do, but I think that the sensible thing to do is to merely
>> document said fact at the instance declaration in the haddocks. This
>> way, the few monads that do support an ArrowLoop instance (most notably
>> the lazy state monad) can keep their instance while everyone else is 
>> warned.
> 
> .... and since the lazy state monad does not fulfill the Functor laws, 
> there is no monad at all, where the ArrowLoop instance is correct?

Ah, I don't intend to haggle over  seq  and  _|_. In my view, the 
ArrowLoop instance for the lazy state monad fulfills the 
right-tightening law just fine.

The trouble is with monads where you cannot a write a function

    first :: (a -> M b) -> ((a,d) -> M (b,d))

that allows you to "lazily observe" the second parameter  d  without 
forcing  a  to some extend. The lazy state monad allows you to write

    first m
       = \p -> m (fst p) >>= \b -> return (b,snd p)
       = \p s -> let (b,s') = m (fst p) s in ((b,snd p),s')

and you can extract the  d  component from the result just fine. But, 
according to the literature, you can't something similar for monads 
where  >>=  is strict in the first argument, like Maybe or [] or IO or 
various monad transformer stacks.


Best regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com




More information about the Libraries mailing list