You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dear computer programmer, you should definitely call execPut inside unsafePerformEffect (if you want to).
The reason why this whole library is Effectful is that ArrayBuffers are mutable, so by default, the ArrayBuffer library functions do everything in Effect to enlist the compiler to confirm that any mutations are properly sequenced.
However, all of the put functions in this library are actually side-effect free, so we can use unsafePerformEffect to tell the compiler to trust that we don't perform any side-effects while we're building an ArrayBuffer.
let pureArrayBuffer :: ArrayBuffer
pureArrayBuffer = serializer 2serializer::Int->ArrayBuffer
serializer x = unsafePerformEffect $ execPut $ do
putInt32be x -- ✅ Good, this has no side-effects
putInt32be =<< getCurrentPosixTime -- ❌ NO NO DON'T DO THIS INSIDE unsafePerformEffect
putArrayBuffer =<< readFileFromMyFilesystem -- ❌ NO WE ARE GONNA GET SO BURNED
Is it a good idea to run
execPut
inunsafePerformEffect
? I suspect that it is a very good idea.The text was updated successfully, but these errors were encountered: