-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add Sodium monad #77
Add Sodium monad #77
Conversation
This approach seems reasonable, given init is idempotent and threadsafe. 🍯 If I were using it I'd probably want a transformer and MonadIO instance, but that'd let me interleave stupid IO things that could affect timing, so maybe it is a good idea to not provide those. Does the library require any cleanup? or does it just leave stuff in the C heap indefinitely |
That's my reasoning too, or part of it. The other part is that I want to keep the surface area of the codebase as minimal/simple as possible, to reduce the complexity of answering "is this thing going to behave sanely in all the ways I can imagine someone using it" for new additions - afaik there's no particular problem with deriving say |
⚒ |
👍 |
Another suggestion would be to have a dummy data type with a hidden constructor, which can only be created by init, and is required by all libsodium functions. |
Thanks, I didn't think of doing that. Tempted to go with this instead of the monad, thoughts @erikd-ambiata @thumphries? |
If users will be making isolated calls to individual Sodium functions, it's not so bad. It does communicate pretty well the fact that you need to set up some abstract FD to use the library. It's nice to make this explicit vs hiding it in some typeclass mechanism. If they will actually be using However, that kinda inverts the design of libsodium, which goes out of its way to have a single global FD that you init early and often. Repeated invocations of tldr I dunno both are good |
Users shouldn't be seeing this at all, regardless of how it's implemented; it's not going to be exported outside
Yep I agree with that. The rhetorical end I have in mind is explicitness and clarity: if I see a function like |
If you are passing a |
They won't be |
I don't have any strong opinions either way, but I am slightly in favour of the monad solution, but thats mainly because it avoids explicit baton passing. |
Closing in favour of #78. |
I don't like this monad much, but it's the nicest way I can think of to ensure
sodiumInit
gets called before everything that needs it (without handling init errors individually everywhere). Other suggestions very welcome.! @thumphries @erikd-ambiata