Skip to content

Add a PrimBase (IOSim s) instance #221

Open

Description

@jorisdral

IOSim has a PrimMonad instance, so I suppose a PrimBase instance could be added too? This would, for example, allow using keepAlive in IOSim

Activity

  1. added
    enhancement
    on Jul 3, 2025
  2. coot commented on Jul 4, 2025

    @coot
    Collaborator

    IOSim is essentially a free monad, one of its operations allows to run ST actions, that would fit into PrimBase, but how would you embed all the other actions into it?

  3. jorisdral commented on Jul 7, 2025

    @jorisdral
    ContributorAuthor

    Right, I posted it here partially to get your input on whether it would be possible. I suppose it isn't, so let's close this issue!

  4. coot commented on Jul 9, 2025

    @coot
    Collaborator

    We could just implement keepAlive, although it's non-trivial. It would require implementing schedule function which can halt and resume:

    class MonadKeepAlive m where
      keepAlive :: a -> m r -> m r
    
    data SimA s a where
      ...
      KeepAlive    :: a -> IOSim s r -> (r -> SimA s b) -> SimA s b
      ...
    
    
    schedule :: _
    schedule thread@Thread { threadControl = ThreadControl action ctl },
             simstate =
      case action of 
        KeepAlive a mr k -> do
          keepAlive a (_ {- here we want to schedule `mr` -})
          _continue {- here we want to continue with `k` -}

    Currently, schedule doesn't allow for something like that. It runs the simulation until completion, while we need some sort of scheduling an IOSim computation in a given computation context. Hopefully, this doesn't become more challenging for IOSimPOR.

  5. coot commented on Jul 9, 2025

    @coot
    Collaborator

    Hmm, another idea would be to implement keepAlive using touch. For it we'd need to push a new kind of frame to the ControlStack.

  6. jorisdral commented on Jul 9, 2025

    @jorisdral
    ContributorAuthor

    I currently don't immediately have a need for keepAlive myself, but I can imagine it might be nice to have. It was more intended as an example

  7. coot commented on Jul 9, 2025

    @coot
    Collaborator

    I'm not sure if it has the correct semantics with regards to exceptions (or that it works correctly), but here's a proof of concept: https://github.com/input-output-hk/io-sim/compare/coot/keepAlive

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions