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

Provide PrimMonad for IOSim and add stToIO to MonadST #141

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

dcoutts
Copy link
Contributor

@dcoutts dcoutts commented Feb 13, 2024

Having IOSim be an instance of PrimMonad (and thus MonadPrim) opens up access to (almost) all of the functionality from the primitive package: including arrays, prim arrays, byte arrays, poiters etc.

The only thing from the primitive package that definately will not work is Data.Primitive.MVar, i.e. real MVars.

And then also use this to make MonadST a lot simpler. By using the PrimState type family we can express the type of stToIO properly:

stToIO :: MonadST m => ST (PrimState m) a -> m a

whereas using withLiftST was very tricky.

@@ -81,6 +81,7 @@ library
containers,
deepseq,
nothunks,
primitive, >=0.7 && <0.10
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
primitive, >=0.7 && <0.10
primitive >=0.7 && <0.10,

io-sim/src/Control/Monad/IOSim/Types.hs Show resolved Hide resolved
io-classes/src/Control/Monad/Class/MonadST.hs Show resolved Hide resolved
@coot coot added io-classes Issues / PRs related to io-classes io-sim Issues / PRs related to io-sim labels Feb 13, 2024
@dcoutts dcoutts requested a review from coot February 14, 2024 09:52
Copy link
Collaborator

@coot coot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, could you squash the commits before merging?

io-sim/src/Control/Monad/IOSim/Types.hs Outdated Show resolved Hide resolved
Having IOSim be an instance of PrimMonad (and thus MonadPrim) opens up
access to (almost) all of the functionality from the primitive package:
including arrays, prim arrays, byte arrays, poiters etc.

The only thing from the primitive package that definately will not work
is Data.Primitive.MVar, i.e. real MVars.

And then also use this to make MonadST a lot simpler. By using the
PrimState type family we can express the type of stToIO properly:

stToIO :: MonadST m => ST (PrimState m) a -> m a

whereas using withLiftST was very tricky.
@dcoutts dcoutts added this pull request to the merge queue Feb 15, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Feb 15, 2024
@dcoutts dcoutts added this pull request to the merge queue Feb 15, 2024
Merged via the queue into main with commit b9b5833 Feb 15, 2024
17 checks passed
@dcoutts dcoutts deleted the dcoutts/primitive-monad branch February 15, 2024 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
io-classes Issues / PRs related to io-classes io-sim Issues / PRs related to io-sim
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants