I fail to see why you would use first class modules for that. What you are "really" trying to use are just functors. Granted the syntax for functors is awful. But if you are not willing to bear with it, then you would expect to have some boilerplate. That said, your types monad and monad_state are the types of a particular monad and a particular state monad (which have certain initiality property). There is no reason for them to be related, which may also be the cause of code duplication.


Arnaud Spiwack


On 23 June 2012 16:32, bob zhang <bobzhang1988@gmail.com> wrote:
Hi List,
   Given the syntax of first class module is improved a lot. I try to encode Monad and MonadState,  http://ideone.com/HgG4M
Unfortunately I found it's still impossible to share the code between differrent Monad Instances. Is it theoretically impossible or I missed something?
   Many thanks

--
-- Bob