Skip to content
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

Use an abstract monad in the linear interfaces #128

Merged
merged 1 commit into from
Nov 15, 2019

Conversation

facundominguez
Copy link
Member

@facundominguez facundominguez commented Jul 25, 2019

The linear interfaces were using Linear.IO, that might not be particularly easy to integrate in applications which use other monads.

I propose here a class to lift non-linear monads into linear monads. jni uses this to offer operations that run on any linear monad that can lift the non-linear IO.

class (Linear.Monad m, NonLinear.Monad (LiftedM m)) => MonadLift m where
  type LiftedM m :: * -> *
  lift :: LiftedM m a -> m a
  liftU :: LiftedM m a -> m (Unrestricted a)

Thus, an application can provide an instance of Linear.Monad for any wrapper of a regularly looking monadic stack. e.g.

data App a = App (ReaderT Env IO a)
  deriving (Monad, Functor, Applicative, MonadIO)

data LinearApp a = LinearApp (App a)

instance Linear.Monad LinearApp where
  ...

instance Linear.MonadLift LinearApp where
  type LiftedM LinearApp = App
  lift = LinearApp
  liftU = LinearApp . fmap Unrestricted

@b-mehta
Copy link

b-mehta commented Aug 22, 2019

This proposal sounds good to me. I think Control.Monad.Lift.Linear in linear-base would be an appropriate place for the MonadLift class, and MonadIO can live in Control.Monad.IO.Class.

@facundominguez
Copy link
Member Author

I have moved the Extra modules for linear-base to tweag/linear-base#64

@facundominguez facundominguez merged commit 5cffa3f into master Nov 15, 2019
@facundominguez facundominguez deleted the fd/abstract-monad branch November 15, 2019 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants