Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
GHC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gesh
GHC
Commits
18e952cf
Commit
18e952cf
authored
25 years ago
by
Simon Peyton Jones
Browse files
Options
Downloads
Patches
Plain Diff
[project @ 1999-09-15 08:00:11 by simonpj]
Extra words about unsafePerformIO
parent
8e346b86
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ghc/docs/libraries/IOExts.sgml
+24
-1
24 additions, 1 deletion
ghc/docs/libraries/IOExts.sgml
with
24 additions
and
1 deletion
ghc/docs/libraries/IOExts.sgml
+
24
−
1
View file @
18e952cf
...
...
@@ -2,11 +2,34 @@
<label id="sec:IOExts">
<p>
(Documetation for this library is sadly inadequate.)
This library provides the following extensions to the IO monad:
<itemize>
<item>
The operations <tt/fixIO/, <tt/unsafePerformIO/ and <tt/unsafeInterleaveIO/
described in <cite id="ImperativeFP">
described in <cite id="ImperativeFP">.
<p>
Everyone knows that if the I/O computation wrapped in <tt/unsafePerformIO/
performs side effects, then the relative order in which those side effects
take place (relative to the main I/O trunk, or other calls to <tt/unsafePerformIO/)
is indeterminate. It is less well known that <tt/unsafePerformIO/ is not type safe.
For example:
<tscreen><verb>
test :: IORef [a]
test = unsafePerformIO $ newIORef []
main = do
writeIORef test [42]
bang <- readIORef test
print (bang :: [Char])
</verb></tscreen>
This program will core dump. This problem with polymorphic references is
well known in the ML community, and does not arise with normal monadic use
of references. There is no easy way to make it impossible once you use
<tt/unsafePerformIO/. Indeed, it is possible to write
<tt>coerce :: a -> b</tt> with the help of <tt/unsafePerformIO/.
So be careful!
<item>
References (aka mutable variables) and mutable arrays (but no form of
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment