Get the latest tech news
Violating memory safety with Haskell's value restriction
Violating memory safety with Haskell's value restriction
IO can create mutable references so we need to prevent it from generalizing them and that’s why the monadic interface imposes something resembling the value restriction. Using this constructor directly can be unsafe, since the illusion of purely modifying the real world (and IO ’s sequencing guarantees) only apply if the State# RealWorld tokens are passed around linearly, i.e. are never duplicated or dropped. Contrary to popular belief, unwrapping the IO constructor is deeply unsafe and can violate memory safety, even if State# tokens are never duplicated or dropped.
Or read this on Hacker News