New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MonadFix for Java monad #739

Open
Supernerd11 opened this Issue Apr 24, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@Supernerd11
Copy link

Supernerd11 commented Apr 24, 2018

Would it be possible to implement MonadFix for the Java monad?

@rahulmutt

This comment has been minimized.

Copy link
Member

rahulmutt commented Apr 24, 2018

The Java monad is isomorphic to the ST monad where the state threads are just raw Java objects.

The implemention of mfix for the ST monad is:

-- | Allow the result of a state transformer computation to be used (lazily)
-- inside the computation.
-- Note that if @f@ is strict, @'fixST' f = _|_@.
fixST :: (a -> ST s a) -> ST s a
fixST k = ST $ \ s ->
    let ans       = liftST (k r) s
        STret _ r = ans
    in
    case ans of STret s' x -> (# s', x #)

It shouldn't be too much trouble to follow the above and write an implementation for the Java monad.

It should probably be added to https://github.com/typelead/eta/blob/master/libraries/base/Java/Core.hs. PRs are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment