Wall of fmaps - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Sridhar Ratnakumar

it just wants to replace the last fmap with <$>

Georgi Lyubenov // googleson78

why not

fmap fmap fmap fmap fmap fmap fmap fmap fmap fmap fmap


Georgi Lyubenov // googleson78

what is the thing being nested so deeply, is this in an instance declaration?

Sridhar Ratnakumar

It is from ka.srid.ca, which is not open source yet. Attaching the code with context. Basically it calls all the plugins, and accumulates their results, uniformly. Since the plugin API is not finalized, and is stil in flux, I left the code un-refactored for now ...

  renderE <-
    mergeWith (flip Map.union)
      <$> sequence
        -- TODO: Eventually create a proper Plugin type to hold these functions.
        [ (fmap . fmap . fmap . fmap . fmap . fmap) (\x -> ThingVal_Pandoc :=> Identity x) $ pure pandocWithScopeE,
          (fmap . fmap . fmap . fmap . fmap) (\x -> (currTime, ThingVal_Calendar :=> Identity x)) $ Calendar.runPlugin graphD pandocD pandocWithScopeE,
          (fmap . fmap . fmap . fmap . fmap) (\x -> (currTime, ThingVal_Tasks :=> Identity x)) $ Task.runPlugin graphD pandocD pandocWithScopeE


Sridhar Ratnakumar

The types are reflex events and dynamics, which look like:

m (Dynamic t (Map ThingName (ThingScope, (UTCTime, Pandoc))))
Sridhar Ratnakumar

The calendar plugin (second line) for example is defined like:

runPlugin ::
  forall t m.
  ( Reflex t,
    MonadHold t m,
    MonadFix m,
    DomBuilder t m
  ) =>
  Dynamic t Graph ->
  Dynamic t (Map ThingName (ThingScope, (UTCTime, Pandoc))) ->
  Event t (Map ThingName (Maybe (ThingScope, (UTCTime, Pandoc)))) ->
  m (Event t (Map ThingName (Maybe (ThingScope, Set Day))))