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

Binding for co-log #10

Open
mmhat opened this issue Oct 18, 2021 · 4 comments
Open

Binding for co-log #10

mmhat opened this issue Oct 18, 2021 · 4 comments
Labels
bindings:new Idea for new bindings

Comments

@mmhat
Copy link
Collaborator

mmhat commented Oct 18, 2021

co-log

@mmhat mmhat added the bindings:new Idea for new bindings label Oct 22, 2021
@ambroslins
Copy link

Hi, I would like to work on this issue, but I am stuck on choosing the right Monad m for the LogAction m msg.

After some trying around I came up with this:

data Log :: (Type -> Type) -> Type -> Effect

type instance DispatchOf (Log m msg) = 'Static

data instance StaticRep (Log m msg) = Log (LogAction m msg)

runLog :: LogAction (Eff es) msg -> Eff (Log (Eff es) msg ': es) a -> Eff es a
runLog = evalStaticRep . Log

logMsg :: Log (Eff es) msg :> es => msg -> Eff es ()
logMsg msg = do
  Log (LogAction action) <- getStaticRep
  action msg

However this does not work because the Log effect will always contain itself.
I think for this to work a subset like typeclass is required, like this:

logMsg :: (Log (Eff logEffects) msg :> allEffects, Subset logEffects allEffects) => msg -> Eff allEffects ()

Another way i can think of is just fixing the Monad to IO (or Eff [IOE]), like:

data Log :: Type -> Effect
data instance StaticRep (Log  msg) = Log (LogAction IO msg)

I think, if the Reader effect would provide a MonadReader instance, most functions from co-log would just work with WithLog.

Basically my question is: what is the best way to move forward?

@ambroslins
Copy link

Looks like this will be solved soon: haskell-effectful/effectful#52

I will use this new class as the Subset class I proposed.

@arybczak
Copy link

arybczak commented Jan 21, 2022

I don't think it's going to work as you'd expect it to.

I'm not familiar with co-log, but from what I see from briefly looking at hackage docs you should carry LogAction IO msg and execute it in logMsg using unsafeEff. You also then need the runLog function to have an IOE :> es constraint for safety (it's going to be described in the documentation of static effects, which is not yet done, but basically if any of static effect operations uses unsafeEff to introduce side effects, the run function needs to require IOE).

Also the StaticRep instance should be a newtype, not a data.

@ambroslins
Copy link

Thanks for the feedback.
You are right, this does not work as I expected, the logEffects would be ambiguous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bindings:new Idea for new bindings
Projects
None yet
Development

No branches or pull requests

3 participants