-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathLinear.hs
More file actions
77 lines (70 loc) · 1.95 KB
/
Linear.hs
File metadata and controls
77 lines (70 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
-- | This module defines an IO monad for linearly working with system resources
-- like files. It provides tools to take resources that are currently
-- unsafely accessible from "System.IO" and use them in this monad.
--
-- Import this module qualified to avoid name clashes.
--
-- To use this RIO monad, create some @RIO@ computation,
-- run it to get a "System.IO" computation.
--
-- = A simple example
-- >>> :set -XLinearTypes
-- >>> :set -XQualifiedDo
-- >>> :set -XNoImplicitPrelude
-- >>> import qualified System.IO.Resource.Linear as Linear
-- >>> import qualified Control.Functor.Linear as Control
-- >>> import qualified Data.Text as Text
-- >>> import Prelude.Linear
-- >>> import qualified Prelude
-- >>> :{
-- linearWriteToFile :: IO ()
-- linearWriteToFile = Linear.run $ Control.do
-- handle1 <- Linear.openFile "/home/user/test.txt" Linear.WriteMode
-- handle2 <- Linear.hPutStrLn handle1 (Text.pack "hello there")
-- () <- Linear.hClose handle2
-- Control.return (Ur ())
-- :}
--
-- To enable do notation, `QualifiedDo` extension is used. But since QualifiedDo
-- only modifies the desugaring of binds, we still need to qualify `Control.return`.
module System.IO.Resource.Linear
( -- * The Resource I/O Monad
RIO,
run,
-- * Interfacing with IO
fromIO,
fromSystemIO,
fromSystemIOU,
-- * Using Resource Handles
-- $monad
-- $files
Handle,
-- ** File I/O
openFile,
openBinaryFile,
System.IOMode (..),
-- ** Working with Handles
hClose,
hIsEOF,
hGetChar,
hPutChar,
hGetLine,
hPutStr,
hPutStrLn,
hSeek,
System.SeekMode (..),
hTell,
-- * Creating new types of resources
-- $new-resources
Resource,
release,
unsafeAcquire,
unsafeFromSystemIOResource,
unsafeFromSystemIOResource_,
-- * Deprecated symbols
UnsafeResource,
unsafeRelease,
)
where
import qualified System.IO as System
import System.IO.Resource.Linear.Internal