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
6a515e89
Commit
6a515e89
authored
27 years ago
by
Simon Marlow
Browse files
Options
Downloads
Patches
Plain Diff
[project @ 1997-11-24 15:43:22 by simonm]
implement STArray using newtype instead of type.
parent
9371efc1
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ghc/lib/glaExts/ST.lhs
+20
-10
20 additions, 10 deletions
ghc/lib/glaExts/ST.lhs
with
20 additions
and
10 deletions
ghc/lib/glaExts/ST.lhs
+
20
−
10
View file @
6a515e89
...
...
@@ -42,7 +42,8 @@ import Ix
%*********************************************************
\begin{code}
newtype STRef s a = STRef (MutableVar s a) deriving Eq
newtype STRef s a = STRef (MutableVar s a)
deriving Eq
newSTRef :: a -> ST s (STRef s a)
newSTRef v = newVar v >>= \ var -> return (STRef var)
...
...
@@ -61,7 +62,8 @@ writeSTRef (STRef var) v = writeVar var v
%*********************************************************
\begin{code}
type STArray s ix elt = MutableArray s ix elt
newtype STArray s ix elt = STArray (MutableArray s ix elt)
deriving Eq
newSTArray :: Ix ix => (ix,ix) -> elt -> ST s (STArray s ix elt)
writeSTArray :: Ix ix => STArray s ix elt -> ix -> elt -> ST s ()
...
...
@@ -71,12 +73,20 @@ thawSTArray :: Ix ix => Array ix elt -> ST s (STArray s ix elt)
freezeSTArray :: Ix ix => STArray s ix elt -> ST s (Array ix elt)
unsafeFreezeSTArray :: Ix ix => STArray s ix elt -> ST s (Array ix elt)
newSTArray = newArray
boundsSTArray = boundsOfArray
readSTArray = readArray
writeSTArray = writeArray
thawSTArray = thawArray
freezeSTArray = freezeArray
unsafeFreezeSTArray = unsafeFreezeArray
newSTArray ixs elt =
newArray ixs elt >>= \arr ->
return (STArray arr)
boundsSTArray (STArray arr) = boundsOfArray arr
readSTArray (STArray arr) ix = readArray arr ix
writeSTArray (STArray arr) ix elt = writeArray arr ix elt
thawSTArray arr = thawArray arr >>= \starr -> return (STArray starr)
freezeSTArray (STArray arr) = freezeArray arr
unsafeFreezeSTArray (STArray arr) = unsafeFreezeArray arr
\end{code}
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