purescript-node/purescript-node-buffer

Should toString have a buffer effect?

Closed this issue · 2 comments

Should the toString function eliminate the BUFFER effect?

Since it converts it to a string there's no more potential for side effects. So should it be something like forall e. Eff ( | e ) String or just String?

paf31 commented

I think buffers are mutable, in which case the effect makes sense.

Yeah.. after thinking about it a little more I think you're right. Any side effect in the buffer will affect code further into the program, even if it is converted to a string:

exclaim :: String -> String
exclaim x = x <> "!"

msg :: forall e. Eff ( buffer :: BUFFER | e ) String
msg = fromString "foo" UTF8

-- scenario 1: no additional mutations happen on the buffer
-- scenario 2: underlying buffer gets mutated to string "bar" as UTF8

-- assuming toString removes the effect, at which point you would assume side effects 
-- wouldn't affect further code
msg' :: String
msg' = runPure $ toString UTF8 msg

main = log $ exclaim msg'
-- scenario 1: logs "foo!"
-- scenario 2: logs "bar!"