Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
GHC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
4,243
Issues
4,243
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
387
Merge Requests
387
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
a61aedc7
Commit
a61aedc7
authored
May 16, 2011
by
dterei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SafeHaskell: Added SafeHaskell to base
parent
19165619
Changes
168
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
168 changed files
with
1176 additions
and
482 deletions
+1176
-482
libraries/base/Control/Applicative.hs
libraries/base/Control/Applicative.hs
+3
-2
libraries/base/Control/Arrow.hs
libraries/base/Control/Arrow.hs
+1
-0
libraries/base/Control/Category.hs
libraries/base/Control/Category.hs
+1
-0
libraries/base/Control/Concurrent.hs
libraries/base/Control/Concurrent.hs
+1
-0
libraries/base/Control/Concurrent/Chan.hs
libraries/base/Control/Concurrent/Chan.hs
+1
-0
libraries/base/Control/Concurrent/MVar.hs
libraries/base/Control/Concurrent/MVar.hs
+1
-0
libraries/base/Control/Concurrent/QSem.hs
libraries/base/Control/Concurrent/QSem.hs
+1
-0
libraries/base/Control/Concurrent/QSemN.hs
libraries/base/Control/Concurrent/QSemN.hs
+1
-0
libraries/base/Control/Concurrent/SampleVar.hs
libraries/base/Control/Concurrent/SampleVar.hs
+1
-0
libraries/base/Control/Exception.hs
libraries/base/Control/Exception.hs
+1
-0
libraries/base/Control/Exception/Base.hs
libraries/base/Control/Exception/Base.hs
+2
-1
libraries/base/Control/Monad.hs
libraries/base/Control/Monad.hs
+1
-0
libraries/base/Control/Monad/Fix.hs
libraries/base/Control/Monad/Fix.hs
+1
-0
libraries/base/Control/Monad/Group.hs
libraries/base/Control/Monad/Group.hs
+1
-0
libraries/base/Control/Monad/Instances.hs
libraries/base/Control/Monad/Instances.hs
+1
-0
libraries/base/Control/Monad/ST.hs
libraries/base/Control/Monad/ST.hs
+28
-45
libraries/base/Control/Monad/ST/Imp.hs
libraries/base/Control/Monad/ST/Imp.hs
+72
-0
libraries/base/Control/Monad/ST/Lazy.hs
libraries/base/Control/Monad/ST/Lazy.hs
+21
-126
libraries/base/Control/Monad/ST/Lazy/Imp.hs
libraries/base/Control/Monad/ST/Lazy/Imp.hs
+162
-0
libraries/base/Control/Monad/ST/Lazy/Safe.hs
libraries/base/Control/Monad/ST/Lazy/Safe.hs
+36
-0
libraries/base/Control/Monad/ST/Lazy/Unsafe.hs
libraries/base/Control/Monad/ST/Lazy/Unsafe.hs
+26
-0
libraries/base/Control/Monad/ST/Safe.hs
libraries/base/Control/Monad/ST/Safe.hs
+33
-0
libraries/base/Control/Monad/ST/Strict.hs
libraries/base/Control/Monad/ST/Strict.hs
+10
-1
libraries/base/Control/Monad/ST/Unsafe.hs
libraries/base/Control/Monad/ST/Unsafe.hs
+27
-0
libraries/base/Control/Monad/Zip.hs
libraries/base/Control/Monad/Zip.hs
+1
-0
libraries/base/Control/OldException.hs
libraries/base/Control/OldException.hs
+1
-0
libraries/base/Data/Bits.hs
libraries/base/Data/Bits.hs
+1
-0
libraries/base/Data/Bool.hs
libraries/base/Data/Bool.hs
+1
-0
libraries/base/Data/Char.hs
libraries/base/Data/Char.hs
+1
-0
libraries/base/Data/Complex.hs
libraries/base/Data/Complex.hs
+1
-0
libraries/base/Data/Either.hs
libraries/base/Data/Either.hs
+1
-0
libraries/base/Data/Eq.hs
libraries/base/Data/Eq.hs
+1
-0
libraries/base/Data/Fixed.hs
libraries/base/Data/Fixed.hs
+1
-0
libraries/base/Data/Foldable.hs
libraries/base/Data/Foldable.hs
+1
-0
libraries/base/Data/Function.hs
libraries/base/Data/Function.hs
+1
-0
libraries/base/Data/Functor.hs
libraries/base/Data/Functor.hs
+1
-0
libraries/base/Data/HashTable.hs
libraries/base/Data/HashTable.hs
+1
-0
libraries/base/Data/IORef.hs
libraries/base/Data/IORef.hs
+1
-1
libraries/base/Data/Int.hs
libraries/base/Data/Int.hs
+1
-0
libraries/base/Data/Ix.hs
libraries/base/Data/Ix.hs
+1
-0
libraries/base/Data/List.hs
libraries/base/Data/List.hs
+1
-0
libraries/base/Data/Maybe.hs
libraries/base/Data/Maybe.hs
+1
-0
libraries/base/Data/Monoid.hs
libraries/base/Data/Monoid.hs
+1
-0
libraries/base/Data/Ord.hs
libraries/base/Data/Ord.hs
+1
-0
libraries/base/Data/Ratio.hs
libraries/base/Data/Ratio.hs
+1
-0
libraries/base/Data/STRef.hs
libraries/base/Data/STRef.hs
+1
-0
libraries/base/Data/STRef/Lazy.hs
libraries/base/Data/STRef/Lazy.hs
+2
-1
libraries/base/Data/STRef/Strict.hs
libraries/base/Data/STRef/Strict.hs
+1
-0
libraries/base/Data/String.hs
libraries/base/Data/String.hs
+1
-0
libraries/base/Data/Traversable.hs
libraries/base/Data/Traversable.hs
+1
-0
libraries/base/Data/Tuple.hs
libraries/base/Data/Tuple.hs
+1
-0
libraries/base/Data/Typeable.hs
libraries/base/Data/Typeable.hs
+1
-1
libraries/base/Data/Unique.hs
libraries/base/Data/Unique.hs
+1
-0
libraries/base/Data/Version.hs
libraries/base/Data/Version.hs
+1
-0
libraries/base/Data/Word.hs
libraries/base/Data/Word.hs
+1
-0
libraries/base/Foreign.hs
libraries/base/Foreign.hs
+18
-1
libraries/base/Foreign/C.hs
libraries/base/Foreign/C.hs
+1
-0
libraries/base/Foreign/C/Error.hs
libraries/base/Foreign/C/Error.hs
+1
-0
libraries/base/Foreign/C/String.hs
libraries/base/Foreign/C/String.hs
+1
-0
libraries/base/Foreign/C/Types.hs
libraries/base/Foreign/C/Types.hs
+1
-0
libraries/base/Foreign/Concurrent.hs
libraries/base/Foreign/Concurrent.hs
+5
-5
libraries/base/Foreign/ForeignPtr.hs
libraries/base/Foreign/ForeignPtr.hs
+18
-156
libraries/base/Foreign/ForeignPtr/Imp.hs
libraries/base/Foreign/ForeignPtr/Imp.hs
+180
-0
libraries/base/Foreign/ForeignPtr/Safe.hs
libraries/base/Foreign/ForeignPtr/Safe.hs
+55
-0
libraries/base/Foreign/ForeignPtr/Unsafe.hs
libraries/base/Foreign/ForeignPtr/Unsafe.hs
+28
-0
libraries/base/Foreign/Marshal.hs
libraries/base/Foreign/Marshal.hs
+4
-0
libraries/base/Foreign/Marshal/Alloc.hs
libraries/base/Foreign/Marshal/Alloc.hs
+1
-0
libraries/base/Foreign/Marshal/Array.hs
libraries/base/Foreign/Marshal/Array.hs
+1
-0
libraries/base/Foreign/Marshal/Error.hs
libraries/base/Foreign/Marshal/Error.hs
+1
-1
libraries/base/Foreign/Marshal/Pool.hs
libraries/base/Foreign/Marshal/Pool.hs
+1
-0
libraries/base/Foreign/Marshal/Safe.hs
libraries/base/Foreign/Marshal/Safe.hs
+36
-0
libraries/base/Foreign/Marshal/Unsafe.hs
libraries/base/Foreign/Marshal/Unsafe.hs
+49
-0
libraries/base/Foreign/Marshal/Utils.hs
libraries/base/Foreign/Marshal/Utils.hs
+1
-0
libraries/base/Foreign/Ptr.hs
libraries/base/Foreign/Ptr.hs
+1
-1
libraries/base/Foreign/Safe.hs
libraries/base/Foreign/Safe.hs
+40
-0
libraries/base/Foreign/StablePtr.hs
libraries/base/Foreign/StablePtr.hs
+1
-0
libraries/base/Foreign/Storable.hs
libraries/base/Foreign/Storable.hs
+1
-0
libraries/base/GHC/Arr.lhs
libraries/base/GHC/Arr.lhs
+22
-3
libraries/base/GHC/Base.lhs
libraries/base/GHC/Base.lhs
+4
-3
libraries/base/GHC/Classes.hs
libraries/base/GHC/Classes.hs
+1
-1
libraries/base/GHC/Conc/Signal.hs
libraries/base/GHC/Conc/Signal.hs
+3
-2
libraries/base/GHC/ConsoleHandler.hs
libraries/base/GHC/ConsoleHandler.hs
+1
-0
libraries/base/GHC/Constants.hs
libraries/base/GHC/Constants.hs
+1
-0
libraries/base/GHC/Desugar.hs
libraries/base/GHC/Desugar.hs
+1
-0
libraries/base/GHC/Enum.lhs
libraries/base/GHC/Enum.lhs
+1
-0
libraries/base/GHC/Environment.hs
libraries/base/GHC/Environment.hs
+1
-0
libraries/base/GHC/Err.lhs
libraries/base/GHC/Err.lhs
+1
-0
libraries/base/GHC/Err.lhs-boot
libraries/base/GHC/Err.lhs-boot
+1
-0
libraries/base/GHC/Event.hs
libraries/base/GHC/Event.hs
+1
-0
libraries/base/GHC/Exception.lhs
libraries/base/GHC/Exception.lhs
+1
-0
libraries/base/GHC/Exts.hs
libraries/base/GHC/Exts.hs
+0
-1
libraries/base/GHC/Float.lhs
libraries/base/GHC/Float.lhs
+1
-0
libraries/base/GHC/Float/ConversionUtils.hs
libraries/base/GHC/Float/ConversionUtils.hs
+1
-0
libraries/base/GHC/Float/RealFracMethods.hs
libraries/base/GHC/Float/RealFracMethods.hs
+1
-0
libraries/base/GHC/Foreign.hs
libraries/base/GHC/Foreign.hs
+1
-0
libraries/base/GHC/Handle.hs
libraries/base/GHC/Handle.hs
+2
-0
libraries/base/GHC/IO.hs
libraries/base/GHC/IO.hs
+12
-12
libraries/base/GHC/IO/Buffer.hs
libraries/base/GHC/IO/Buffer.hs
+1
-0
libraries/base/GHC/IO/BufferedIO.hs
libraries/base/GHC/IO/BufferedIO.hs
+4
-4
libraries/base/GHC/IO/Device.hs
libraries/base/GHC/IO/Device.hs
+6
-5
libraries/base/GHC/IO/Encoding.hs
libraries/base/GHC/IO/Encoding.hs
+10
-10
libraries/base/GHC/IO/Encoding.hs-boot
libraries/base/GHC/IO/Encoding.hs-boot
+2
-1
libraries/base/GHC/IO/Encoding/CodePage.hs
libraries/base/GHC/IO/Encoding/CodePage.hs
+1
-0
libraries/base/GHC/IO/Encoding/Failure.hs
libraries/base/GHC/IO/Encoding/Failure.hs
+1
-0
libraries/base/GHC/IO/Encoding/Iconv.hs
libraries/base/GHC/IO/Encoding/Iconv.hs
+2
-1
libraries/base/GHC/IO/Encoding/Latin1.hs
libraries/base/GHC/IO/Encoding/Latin1.hs
+1
-0
libraries/base/GHC/IO/Encoding/Types.hs
libraries/base/GHC/IO/Encoding/Types.hs
+1
-0
libraries/base/GHC/IO/Encoding/UTF16.hs
libraries/base/GHC/IO/Encoding/UTF16.hs
+1
-0
libraries/base/GHC/IO/Encoding/UTF32.hs
libraries/base/GHC/IO/Encoding/UTF32.hs
+1
-0
libraries/base/GHC/IO/Encoding/UTF8.hs
libraries/base/GHC/IO/Encoding/UTF8.hs
+1
-0
libraries/base/GHC/IO/Exception.hs
libraries/base/GHC/IO/Exception.hs
+1
-0
libraries/base/GHC/IO/Exception.hs-boot
libraries/base/GHC/IO/Exception.hs-boot
+1
-0
libraries/base/GHC/IO/FD.hs
libraries/base/GHC/IO/FD.hs
+7
-8
libraries/base/GHC/IO/Handle.hs
libraries/base/GHC/IO/Handle.hs
+1
-0
libraries/base/GHC/IO/Handle.hs-boot
libraries/base/GHC/IO/Handle.hs-boot
+1
-0
libraries/base/GHC/IO/Handle/FD.hs
libraries/base/GHC/IO/Handle/FD.hs
+3
-5
libraries/base/GHC/IO/Handle/FD.hs-boot
libraries/base/GHC/IO/Handle/FD.hs-boot
+1
-0
libraries/base/GHC/IO/Handle/Internals.hs
libraries/base/GHC/IO/Handle/Internals.hs
+2
-2
libraries/base/GHC/IO/Handle/Text.hs
libraries/base/GHC/IO/Handle/Text.hs
+6
-5
libraries/base/GHC/IO/Handle/Types.hs
libraries/base/GHC/IO/Handle/Types.hs
+1
-0
libraries/base/GHC/IO/IOMode.hs
libraries/base/GHC/IO/IOMode.hs
+1
-0
libraries/base/GHC/IOArray.hs
libraries/base/GHC/IOArray.hs
+10
-9
libraries/base/GHC/IORef.hs
libraries/base/GHC/IORef.hs
+4
-4
libraries/base/GHC/Int.hs
libraries/base/GHC/Int.hs
+3
-2
libraries/base/GHC/List.lhs
libraries/base/GHC/List.lhs
+1
-0
libraries/base/GHC/MVar.hs
libraries/base/GHC/MVar.hs
+7
-8
libraries/base/GHC/Num.lhs
libraries/base/GHC/Num.lhs
+1
-0
libraries/base/GHC/PArr.hs
libraries/base/GHC/PArr.hs
+1
-0
libraries/base/GHC/Ptr.lhs
libraries/base/GHC/Ptr.lhs
+9
-2
libraries/base/GHC/Read.lhs
libraries/base/GHC/Read.lhs
+2
-1
libraries/base/GHC/Real.lhs
libraries/base/GHC/Real.lhs
+1
-0
libraries/base/GHC/ST.lhs
libraries/base/GHC/ST.lhs
+7
-1
libraries/base/GHC/STRef.lhs
libraries/base/GHC/STRef.lhs
+6
-2
libraries/base/GHC/Show.lhs
libraries/base/GHC/Show.lhs
+1
-0
libraries/base/GHC/Show.lhs-boot
libraries/base/GHC/Show.lhs-boot
+1
-0
libraries/base/GHC/Stable.lhs
libraries/base/GHC/Stable.lhs
+9
-9
libraries/base/GHC/Storable.lhs
libraries/base/GHC/Storable.lhs
+2
-1
libraries/base/GHC/TopHandler.lhs
libraries/base/GHC/TopHandler.lhs
+5
-4
libraries/base/GHC/Unicode.hs
libraries/base/GHC/Unicode.hs
+9
-8
libraries/base/GHC/Unicode.hs-boot
libraries/base/GHC/Unicode.hs-boot
+1
-0
libraries/base/GHC/Weak.lhs
libraries/base/GHC/Weak.lhs
+7
-1
libraries/base/GHC/Windows.hs
libraries/base/GHC/Windows.hs
+5
-1
libraries/base/GHC/Word.hs
libraries/base/GHC/Word.hs
+1
-0
libraries/base/Numeric.hs
libraries/base/Numeric.hs
+1
-0
libraries/base/Prelude.hs
libraries/base/Prelude.hs
+1
-2
libraries/base/System/CPUTime.hsc
libraries/base/System/CPUTime.hsc
+2
-1
libraries/base/System/Console/GetOpt.hs
libraries/base/System/Console/GetOpt.hs
+1
-0
libraries/base/System/Environment.hs
libraries/base/System/Environment.hs
+2
-1
libraries/base/System/Exit.hs
libraries/base/System/Exit.hs
+1
-0
libraries/base/System/IO.hs
libraries/base/System/IO.hs
+1
-0
libraries/base/System/IO/Error.hs
libraries/base/System/IO/Error.hs
+1
-0
libraries/base/System/IO/Unsafe.hs
libraries/base/System/IO/Unsafe.hs
+1
-1
libraries/base/System/Info.hs
libraries/base/System/Info.hs
+1
-0
libraries/base/System/Mem.hs
libraries/base/System/Mem.hs
+1
-0
libraries/base/System/Mem/StableName.hs
libraries/base/System/Mem/StableName.hs
+1
-0
libraries/base/System/Mem/Weak.hs
libraries/base/System/Mem/Weak.hs
+1
-0
libraries/base/System/Posix/Internals.hs
libraries/base/System/Posix/Internals.hs
+1
-0
libraries/base/System/Posix/Internals.hs-boot
libraries/base/System/Posix/Internals.hs-boot
+1
-0
libraries/base/System/Posix/Types.hs
libraries/base/System/Posix/Types.hs
+1
-0
libraries/base/System/Timeout.hs
libraries/base/System/Timeout.hs
+1
-0
libraries/base/Text/ParserCombinators/ReadP.hs
libraries/base/Text/ParserCombinators/ReadP.hs
+1
-0
libraries/base/Text/ParserCombinators/ReadPrec.hs
libraries/base/Text/ParserCombinators/ReadPrec.hs
+1
-0
libraries/base/Text/Printf.hs
libraries/base/Text/Printf.hs
+1
-0
libraries/base/Text/Read.hs
libraries/base/Text/Read.hs
+1
-0
libraries/base/Text/Read/Lex.hs
libraries/base/Text/Read/Lex.hs
+1
-0
libraries/base/Text/Show.hs
libraries/base/Text/Show.hs
+1
-0
libraries/base/Text/Show/Functions.hs
libraries/base/Text/Show/Functions.hs
+1
-0
libraries/base/base.cabal
libraries/base/base.cabal
+33
-19
No files found.
libraries/base/Control/Applicative.hs
View file @
a61aedc7
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP #-}
-----------------------------------------------------------------------------
...
...
@@ -51,8 +52,8 @@ import Control.Arrow (Arrow(arr, (&&&)), ArrowZero(zeroArrow), ArrowPlus((<+>)))
import
Control.Monad
(
liftM
,
ap
,
MonadPlus
(
..
))
import
Control.Monad.Instances
()
#
ifndef
__NHC__
import
Control.Monad.ST
(
ST
)
import
qualified
Control.Monad.ST.Lazy
as
Lazy
(
ST
)
import
Control.Monad.ST
.Safe
(
ST
)
import
qualified
Control.Monad.ST.Lazy
.Safe
as
Lazy
(
ST
)
#
endif
import
Data.Functor
((
<$>
),
(
<$
))
import
Data.Monoid
(
Monoid
(
..
))
...
...
libraries/base/Control/Arrow.hs
View file @
a61aedc7
{-# LANGUAGE Trustworthy #-}
-----------------------------------------------------------------------------
-- |
-- Module : Control.Arrow
...
...
libraries/base/Control/Category.hs
View file @
a61aedc7
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP #-}
-----------------------------------------------------------------------------
...
...
libraries/base/Control/Concurrent.hs
View file @
a61aedc7
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP
, ForeignFunctionInterface
, MagicHash
...
...
libraries/base/Control/Concurrent/Chan.hs
View file @
a61aedc7
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP #-}
#
ifdef
__GLASGOW_HASKELL__
{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
...
...
libraries/base/Control/Concurrent/MVar.hs
View file @
a61aedc7
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP, NoImplicitPrelude #-}
-----------------------------------------------------------------------------
...
...
libraries/base/Control/Concurrent/QSem.hs
View file @
a61aedc7
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP #-}
#
ifdef
__GLASGOW_HASKELL__
{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
...
...
libraries/base/Control/Concurrent/QSemN.hs
View file @
a61aedc7
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP #-}
#
ifdef
__GLASGOW_HASKELL__
{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
...
...
libraries/base/Control/Concurrent/SampleVar.hs
View file @
a61aedc7
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP #-}
#
ifdef
__GLASGOW_HASKELL__
{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
...
...
libraries/base/Control/Exception.hs
View file @
a61aedc7
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP, NoImplicitPrelude, ExistentialQuantification #-}
-----------------------------------------------------------------------------
...
...
libraries/base/Control/Exception/Base.hs
View file @
a61aedc7
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash #-}
#
ifdef
__GLASGOW_HASKELL__
{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
...
...
@@ -400,7 +401,7 @@ catch :: Exception e
->
(
e
->
IO
a
)
-- ^ Handler to invoke if an exception is raised
->
IO
a
#
if
__GLASGOW_HASKELL__
catch
=
GHC
.
IO
.
catchException
catch
=
catchException
#
elif
__HUGS__
catch
m
h
=
Hugs
.
Exception
.
catchException
m
h'
where
h'
e
=
case
fromException
e
of
...
...
libraries/base/Control/Monad.hs
View file @
a61aedc7
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP, NoImplicitPrelude #-}
-----------------------------------------------------------------------------
...
...
libraries/base/Control/Monad/Fix.hs
View file @
a61aedc7
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP #-}
-----------------------------------------------------------------------------
...
...
libraries/base/Control/Monad/Group.hs
View file @
a61aedc7
{-# LANGUAGE Trustworthy #-}
-----------------------------------------------------------------------------
-- |
-- Module : Control.Monad.Group
...
...
libraries/base/Control/Monad/Instances.hs
View file @
a61aedc7
{-# LANGUAGE Safe #-}
{-# OPTIONS_NHC98 --prelude #-}
-- This module deliberately declares orphan instances:
{-# OPTIONS_GHC -fno-warn-orphans #-}
...
...
libraries/base/Control/Monad/ST.hs
View file @
a61aedc7
{-# LANGUAGE CPP #-}
{-# LANGUAGE CPP, SafeImports #-}
#
if
sh_SAFE_DEFAULT
{-# LANGUAGE Safe #-}
#
endif
-----------------------------------------------------------------------------
-- |
-- Module : Control.Monad.ST
-- Copyright : (c) The University of Glasgow 2001
-- License : BSD-style (see the file libraries/base/LICENSE)
--
--
-- Maintainer : libraries@haskell.org
-- Stability : experimental
-- Portability : non-portable (requires universal quantification for runST)
...
...
@@ -16,55 +19,35 @@
--
-----------------------------------------------------------------------------
module
Control.Monad.ST
(
-- * The 'ST' Monad
ST
,
-- abstract, instance of Functor, Monad, Typeable.
runST
,
-- :: (forall s. ST s a) -> a
fixST
,
-- :: (a -> ST s a) -> ST s a
-- * Converting 'ST' to 'IO'
RealWorld
,
-- abstract
stToIO
,
-- :: ST RealWorld a -> IO a
-- * Unsafe operations
unsafeInterleaveST
,
-- :: ST s a -> ST s a
unsafeIOToST
,
-- :: IO a -> ST s a
unsafeSTToIO
-- :: ST s a -> IO a
)
where
#
if
defined
(
__GLASGOW_HASKELL__
)
import
Control.Monad.Fix
()
#
else
import
Control.Monad.Fix
module
Control.Monad.ST
(
module
Control
.
Monad
.
ST
.
Safe
#
if
!
sh_SAFE_DEFAULT
-- * Unsafe Functions
,
unsafeInterleaveST
,
unsafeIOToST
,
unsafeSTToIO
#
endif
)
where
#
include
"Typeable.h"
import
safe
Control
.
Monad
.
ST
.
Safe
#
if
defined
(
__GLASGOW_HASKELL__
)
import
GHC.ST
(
ST
,
runST
,
fixST
,
unsafeInterleaveST
)
import
GHC.Base
(
RealWorld
)
import
GHC.IO
(
stToIO
,
unsafeIOToST
,
unsafeSTToIO
)
#
elif
defined
(
__HUGS__
)
import
Data.Typeable
import
Hugs.ST
import
qualified
Hugs.LazyST
as
LazyST
#
endif
#
if
defined
(
__HUGS__
)
INSTANCE_TYPEABLE2
(
ST
,
sTTc
,
"ST"
)
INSTANCE_TYPEABLE0
(
RealWorld
,
realWorldTc
,
"RealWorld"
)
#
if
!
sh_SAFE_DEFAULT
import
qualified
Control.Monad.ST.Unsafe
as
U
fixST
::
(
a
->
ST
s
a
)
->
ST
s
a
fixST
f
=
LazyST
.
lazyToStrictST
(
LazyST
.
fixST
(
LazyST
.
strictToLazyST
.
f
))
{-# DEPRECATED unsafeInterleaveST, unsafeIOToST, unsafeSTToIO
"Please import from Control.Monad.ST.Unsafe instead; This will be removed in the next release"
#-}
{-# INLINE unsafeInterleaveST #-}
unsafeInterleaveST
::
ST
s
a
->
ST
s
a
unsafeInterleaveST
=
LazyST
.
lazyToStrictST
.
LazyST
.
unsafeInterleaveST
.
LazyST
.
strictToLazyST
#
endif
unsafeInterleaveST
=
U
.
unsafeInterleaveST
{-# INLINE unsafeIOToST #-}
unsafeIOToST
::
IO
a
->
ST
s
a
unsafeIOToST
=
U
.
unsafeIOToST
#
if
!
defined
(
__GLASGOW_HASKELL__
)
instance
MonadFix
(
ST
s
)
where
mfix
=
fixST
{-# INLINE unsafeSTToIO #-}
unsafeSTToIO
::
ST
s
a
->
IO
a
unsafeSTToIO
=
U
.
unsafeSTToIO
#
endif
libraries/base/Control/Monad/ST/Imp.hs
0 → 100644
View file @
a61aedc7
{-# LANGUAGE CPP #-}
{-# OPTIONS_HADDOCK hide #-}
-----------------------------------------------------------------------------
-- |
-- Module : Control.Monad.ST.Imp
-- Copyright : (c) The University of Glasgow 2001
-- License : BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer : libraries@haskell.org
-- Stability : experimental
-- Portability : non-portable (requires universal quantification for runST)
--
-- This library provides support for /strict/ state threads, as
-- described in the PLDI \'94 paper by John Launchbury and Simon Peyton
-- Jones /Lazy Functional State Threads/.
--
-----------------------------------------------------------------------------
-- #hide
module
Control.Monad.ST.Imp
(
-- * The 'ST' Monad
ST
,
-- abstract, instance of Functor, Monad, Typeable.
runST
,
-- :: (forall s. ST s a) -> a
fixST
,
-- :: (a -> ST s a) -> ST s a
-- * Converting 'ST' to 'IO'
RealWorld
,
-- abstract
stToIO
,
-- :: ST RealWorld a -> IO a
-- * Unsafe operations
unsafeInterleaveST
,
-- :: ST s a -> ST s a
unsafeIOToST
,
-- :: IO a -> ST s a
unsafeSTToIO
-- :: ST s a -> IO a
)
where
#
if
defined
(
__GLASGOW_HASKELL__
)
import
Control.Monad.Fix
()
#
else
import
Control.Monad.Fix
#
endif
#
include
"Typeable.h"
#
if
defined
(
__GLASGOW_HASKELL__
)
import
GHC.ST
(
ST
,
runST
,
fixST
,
unsafeInterleaveST
)
import
GHC.Base
(
RealWorld
)
import
GHC.IO
(
stToIO
,
unsafeIOToST
,
unsafeSTToIO
)
#
elif
defined
(
__HUGS__
)
import
Data.Typeable
import
Hugs.ST
import
qualified
Hugs.LazyST
as
LazyST
#
endif
#
if
defined
(
__HUGS__
)
INSTANCE_TYPEABLE2
(
ST
,
sTTc
,
"ST"
)
INSTANCE_TYPEABLE0
(
RealWorld
,
realWorldTc
,
"RealWorld"
)
fixST
::
(
a
->
ST
s
a
)
->
ST
s
a
fixST
f
=
LazyST
.
lazyToStrictST
(
LazyST
.
fixST
(
LazyST
.
strictToLazyST
.
f
))
unsafeInterleaveST
::
ST
s
a
->
ST
s
a
unsafeInterleaveST
=
LazyST
.
lazyToStrictST
.
LazyST
.
unsafeInterleaveST
.
LazyST
.
strictToLazyST
#
endif
#
if
!
defined
(
__GLASGOW_HASKELL__
)
instance
MonadFix
(
ST
s
)
where
mfix
=
fixST
#
endif
libraries/base/Control/Monad/ST/Lazy.hs
View file @
a61aedc7
{-# LANGUAGE CPP, MagicHash, UnboxedTuples, Rank2Types #-}
{-# LANGUAGE CPP, SafeImports #-}
#
if
sh_SAFE_DEFAULT
{-# LANGUAGE Safe #-}
#
endif
-----------------------------------------------------------------------------
-- |
...
...
@@ -17,136 +20,28 @@
-----------------------------------------------------------------------------
module
Control.Monad.ST.Lazy
(
-- * The 'ST' monad
ST
,
runST
,
fixST
,
-- * Converting between strict and lazy 'ST'
strictToLazyST
,
lazyToStrictST
,
-- * Converting 'ST' To 'IO'
RealWorld
,
stToIO
,
-- * Unsafe operations
unsafeInterleaveST
,
unsafeIOToST
)
where
import
Prelude
import
Control.Monad.Fix
import
qualified
Control.Monad.ST
as
ST
#
ifdef
__GLASGOW_HASKELL__
import
qualified
GHC.ST
import
GHC.Base
#
endif
#
ifdef
__HUGS__
import
Hugs.LazyST
module
Control
.
Monad
.
ST
.
Lazy
.
Safe
#
if
!
sh_SAFE_DEFAULT
-- * Unsafe Functions
,
unsafeInterleaveST
,
unsafeIOToST
#
endif
)
where
#
ifdef
__GLASGOW_HASKELL__
-- | The lazy state-transformer monad.
-- A computation of type @'ST' s a@ transforms an internal state indexed
-- by @s@, and returns a value of type @a@.
-- The @s@ parameter is either
--
-- * an unstantiated type variable (inside invocations of 'runST'), or
--
-- * 'RealWorld' (inside invocations of 'stToIO').
--
-- It serves to keep the internal states of different invocations of
-- 'runST' separate from each other and from invocations of 'stToIO'.
--
-- The '>>=' and '>>' operations are not strict in the state. For example,
--
-- @'runST' (writeSTRef _|_ v >>= readSTRef _|_ >> return 2) = 2@
newtype
ST
s
a
=
ST
(
State
s
->
(
a
,
State
s
))
data
State
s
=
S
#
(
State
#
s
)
instance
Functor
(
ST
s
)
where
fmap
f
m
=
ST
$
\
s
->
let
ST
m_a
=
m
(
r
,
new_s
)
=
m_a
s
in
(
f
r
,
new_s
)
instance
Monad
(
ST
s
)
where
return
a
=
ST
$
\
s
->
(
a
,
s
)
m
>>
k
=
m
>>=
\
_
->
k
fail
s
=
error
s
(
ST
m
)
>>=
k
=
ST
$
\
s
->
let
(
r
,
new_s
)
=
m
s
ST
k_a
=
k
r
in
k_a
new_s
{-# NOINLINE runST #-}
-- | Return the value computed by a state transformer computation.
-- The @forall@ ensures that the internal state used by the 'ST'
-- computation is inaccessible to the rest of the program.
runST
::
(
forall
s
.
ST
s
a
)
->
a
runST
st
=
case
st
of
ST
the_st
->
let
(
r
,
_
)
=
the_st
(
S
#
realWorld
#
)
in
r
-- | Allow the result of a state transformer computation to be used (lazily)
-- inside the computation.
-- Note that if @f@ is strict, @'fixST' f = _|_@.
fixST
::
(
a
->
ST
s
a
)
->
ST
s
a
fixST
m
=
ST
(
\
s
->
let
ST
m_r
=
m
r
(
r
,
s'
)
=
m_r
s
in
(
r
,
s'
))
#
endif
instance
MonadFix
(
ST
s
)
where
mfix
=
fixST
-- ---------------------------------------------------------------------------
-- Strict <--> Lazy
#
ifdef
__GLASGOW_HASKELL__
{-|
Convert a strict 'ST' computation into a lazy one. The strict state
thread passed to 'strictToLazyST' is not performed until the result of
the lazy state thread it returns is demanded.
-}
strictToLazyST
::
ST
.
ST
s
a
->
ST
s
a
strictToLazyST
m
=
ST
$
\
s
->
let
pr
=
case
s
of
{
S
#
s
#
->
GHC
.
ST
.
liftST
m
s
#
}
r
=
case
pr
of
{
GHC
.
ST
.
STret
_
v
->
v
}
s'
=
case
pr
of
{
GHC
.
ST
.
STret
s2
#
_
->
S
#
s2
#
}
in
(
r
,
s'
)
import
safe
Control
.
Monad
.
ST
.
Lazy
.
Safe
#
if
!
sh_SAFE_DEFAULT
import
qualified
Control.Monad.ST.Lazy.Unsafe
as
U
{-|
Convert a lazy 'ST' computation into a strict one.
-}
lazyToStrictST
::
ST
s
a
->
ST
.
ST
s
a
lazyToStrictST
(
ST
m
)
=
GHC
.
ST
.
ST
$
\
s
->
case
(
m
(
S
#
s
))
of
(
a
,
S
#
s'
)
->
(
#
s'
,
a
#
)
{-# DEPRECATED unsafeInterleaveST, unsafeIOToST
"Please import from Control.Monad.ST.Lazy.Unsafe instead; This will be removed in the next release"
#-}
{-# INLINE unsafeInterleaveST #-}
unsafeInterleaveST
::
ST
s
a
->
ST
s
a
unsafeInterleaveST
=
strictToLazyST
.
ST
.
unsafeInterleaveST
.
lazyToStrictST
#
endif
unsafeInterleaveST
=
U
.
unsafeInterleaveST
{-# INLINE unsafeIOToST #-}
unsafeIOToST
::
IO
a
->
ST
s
a
unsafeIOToST
=
strictToLazyST
.
ST
.
unsafeIOToST
unsafeIOToST
=
U
.
unsafeIOToST
#
endif
-- | A monad transformer embedding lazy state transformers in the 'IO'
-- monad. The 'RealWorld' parameter indicates that the internal state
-- used by the 'ST' computation is a special one supplied by the 'IO'
-- monad, and thus distinct from those used by invocations of 'runST'.
stToIO
::
ST
RealWorld
a
->
IO
a
stToIO
=
ST
.
stToIO
.
lazyToStrictST
libraries/base/Control/Monad/ST/Lazy/Imp.hs
0 → 100644
View file @
a61aedc7
{-# LANGUAGE CPP, MagicHash, UnboxedTuples, Rank2Types #-}
{-# OPTIONS_HADDOCK hide #-}
-----------------------------------------------------------------------------
-- |
-- Module : Control.Monad.ST.Lazy.Imp
-- Copyright : (c) The University of Glasgow 2001
-- License : BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer : libraries@haskell.org
-- Stability : provisional
-- Portability : non-portable (requires universal quantification for runST)
--
-- This module presents an identical interface to "Control.Monad.ST",
-- except that the monad delays evaluation of state operations until
-- a value depending on them is required.
--
-----------------------------------------------------------------------------
-- #hide
module
Control.Monad.ST.Lazy.Imp
(
-- * The 'ST' monad
ST
,
runST
,
fixST
,
-- * Converting between strict and lazy 'ST'
strictToLazyST
,
lazyToStrictST
,
-- * Converting 'ST' To 'IO'
RealWorld
,
stToIO
,
-- * Unsafe operations
unsafeInterleaveST
,
unsafeIOToST
)
where
import
Prelude
import
Control.Monad.Fix
import
qualified
Control.Monad.ST.Safe
as
ST
import
qualified
Control.Monad.ST.Unsafe
as
ST
#
ifdef
__GLASGOW_HASKELL__
import
qualified
GHC.ST
as
GHC.ST
import
GHC.Base
#
endif
#
ifdef
__HUGS__
import
Hugs.LazyST
#
endif
#
ifdef
__GLASGOW_HASKELL__
-- | The lazy state-transformer monad.
-- A computation of type @'ST' s a@ transforms an internal state indexed
-- by @s@, and returns a value of type @a@.
-- The @s@ parameter is either
--
-- * an unstantiated type variable (inside invocations of 'runST'), or
--
-- * 'RealWorld' (inside invocations of 'stToIO').
--
-- It serves to keep the internal states of different invocations of
-- 'runST' separate from each other and from invocations of 'stToIO'.
--
-- The '>>=' and '>>' operations are not strict in the state. For example,
--
-- @'runST' (writeSTRef _|_ v >>= readSTRef _|_ >> return 2) = 2@
newtype
ST
s
a
=
ST
(
State
s
->
(
a
,
State
s
))
data
State
s
=
S
#
(
State
#
s
)
instance
Functor
(
ST
s
)
where
fmap
f
m
=
ST
$
\
s
->
let
ST
m_a
=
m
(
r
,
new_s
)
=
m_a
s
in
(
f
r
,
new_s
)
instance
Monad
(
ST
s
)
where
return
a
=
ST
$
\
s
->
(
a
,
s
)
m
>>
k
=
m
>>=
\
_
->
k
fail
s
=
error
s
(
ST
m
)
>>=
k
=
ST
$
\
s
->
let
(
r
,
new_s
)
=
m
s
ST
k_a
=
k
r
in
k_a
new_s
{-# NOINLINE runST #-}
-- | Return the value computed by a state transformer computation.
-- The @forall@ ensures that the internal state used by the 'ST'
-- computation is inaccessible to the rest of the program.
runST
::
(
forall
s
.
ST
s
a
)
->
a
runST
st
=
case
st
of
ST
the_st
->
let
(
r
,
_
)
=
the_st
(
S
#
realWorld
#
)
in
r
-- | Allow the result of a state transformer computation to be used (lazily)
-- inside the computation.
-- Note that if @f@ is strict, @'fixST' f = _|_@.
fixST
::
(
a
->
ST
s
a
)
->
ST
s
a
fixST
m
=
ST
(
\
s
->
let
ST
m_r
=
m
r
(
r
,
s'
)
=
m_r
s
in
(
r
,
s'
))
#
endif
instance
MonadFix
(
ST
s
)
where
mfix
=
fixST
-- ---------------------------------------------------------------------------
-- Strict <--> Lazy
#
ifdef
__GLASGOW_HASKELL__
{-|
Convert a strict 'ST' computation into a lazy one. The strict state
thread passed to 'strictToLazyST' is not performed until the result of
the lazy state thread it returns is demanded.
-}
strictToLazyST
::
ST
.
ST
s
a
->
ST
s
a
strictToLazyST
m
=
ST
$
\
s
->
let
pr
=
case
s
of
{
S
#
s
#
->
GHC
.
ST
.
liftST
m
s
#
}
r
=
case
pr
of
{
GHC
.
ST
.
STret
_
v
->
v
}
s'
=
case
pr
of
{
GHC
.
ST
.
STret
s2
#
_
->
S
#
s2
#
}
in
(
r
,
s'
)
{-|
Convert a lazy 'ST' computation into a strict one.
-}