Skip to content

Zooming in the Effect(Core) monad / exporting EffectCore #953

@noinia

Description

@noinia

Is your feature request related to a problem? Please describe.

I'm trying to update some of my code to the new miso 1.9 setup. However, I'm getting stuck / I don't think miso currently exports everything I need in order to update. Before, my code looked something like this (this example is somewhat simplified):

type Field = ... 
data Model = Model { _field :: Field } 
makeLenses ''Model
data MyAction = ... 

fieldUpdate :: Field -> MyAction -> Effect action Field

update           :: Model -> MyAction -> Effect action Model 
update m act = m&field %%~ flip fieldUpdate act 

I think the solution would now need to look something along the lines of:

fieldUpdate :: MyAction -> Effect Field action 
fieldUpdate = .. 

update       :: MyAction -> Effect Model action 
update act = zoom field $ fieldUpdate action

but for that EffectCore needs to be an instance of Zoom (from the lens package). However, I cannot implement that instance as miso is not exporting EffectCore. None of the other lensy type combinators seemed to apply for this case, i.e %= or .= take a pure function or value rather than a monadic one.

Describe the solution you'd like

  1. At least export EffectCore so that I can implement the appropriate Zoom instance for EffectCore; furthermore, it is currently hard to figure out what functionality Effect has, since one can only see the MonadState/Reader etc. instances when looking at the source code.
  2. I would maybe even have expected some custom lifting function for this case; I would expect it to be rather common.

In all honesty: I don't really like the new 'Effect' setup; I tend to think of update essentially as a function 'model -> action -> model' that can additionally schedule some new actions. The previous type captured that perfectly, whereas the current type seems to push me towards update as something of type "action -> action" that may additionally modify the model. I find that unnatural: I would much rather have / pass / manipulate the model values explicitly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions