Copyright | (c) Alias Qli 2022 |
---|---|
License | BSD-3-Clause |
Maintainer | 2576814881@qq.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module implements stream-based I/O as described in Haskell Report 1.2.
As th resport says, "Haskell's I/O system is based on the view that a program communicates to the outside world via streams of messages: a program issues a stream of requests to the operating system and in return receives a stream of responses." And a stream in Haskell is only a lazy list.
Synopsis
- type Dialogue = [Response] -> [Request]
- data Request
- = ReadFile Name
- | WriteFile Name String
- | AppendFile Name String
- | ReadBinFile Name
- | WriteBinFile Name Bin
- | AppendBinFile Name Bin
- | DeleteFile Name
- | StatusFile Name
- | ReadChan Name
- | AppendChan Name String
- | ReadBinChan Name
- | AppendBinChan Name Bin
- | StatusChan Name
- | Echo Bool
- | GetArgs
- | GetProgName
- | GetEnv Name
- | SetEnv Name String
- type Bin = ByteString
- nullBin :: Bin
- appendBin :: Bin -> Bin -> Bin
- isNullBin :: Bin -> Bool
- type Name = String
- stdin :: Name
- stdout :: Name
- stderr :: Name
- stdecho :: Name
- data Response
- data IOError
- runDialogue :: Dialogue -> IO ()
The Program Type
Request Types
Requests a program may issue.
ReadFile Name |
|
WriteFile Name String |
This request is "hyperstrict" in its second argument: no response is returned until the entire list of values is completely evaluated. |
AppendFile Name String | Identicle to
All other errors have form |
ReadBinFile Name | Similar to |
WriteBinFile Name Bin | Similar to |
AppendBinFile Name Bin | Similar to |
DeleteFile Name |
|
StatusFile Name |
For example, "dr--" denotes a directory that can be read but not written or executed. |
ReadChan Name |
Unlike files, once a Known issue: This request would leave the handle behind the channel in semi-closed state,
causing any other attempt to read from the channel to fail. This should be problematic if your program
issued an request to read from
|
AppendChan Name String |
All other errors have form |
ReadBinChan Name | Similar to |
AppendBinChan Name Bin | Similar to |
StatusChan Name |
|
Echo Bool |
The report requires that the echo mode can only be set once by a particular program, before any
I/O operation involving Known issue: It's currently implemented as |
GetArgs | Induces the response |
GetProgName | Returns the short name of the current program, not including search path information. If successful,
the response will be of the form |
GetEnv Name |
|
SetEnv Name String |
|
The Binary Type
type Bin = ByteString Source #
Bin
is a datatype for binary values, as required by the report, and is implemented as a lazy ByteString
.
The Name
Type
This type synonym is described in Haskell Report 1.0, and exists for backward compatibility.
Channels
Response Types
Responses a program may receive.
WriteError String | |
ReadError String | |
SearchError String | |
FormatError String | Since we're using a modern device and the maximum line length and page length allowed on the channel have no bound, this error would never occur. |
OtherError String |
Run the Program
runDialogue :: Dialogue -> IO () Source #
The central function to run a program.