APIIO

IO

Permission for real native interaction, with structured errors and line data. Console owns the standard streams; File owns file handles. Generic byte IO uses Bytes.Source and Bytes.Sink rather than a shared handle.

Error

type Error =    { kind : Kind    , path : String    , message : String    }Source

A structured IO failure.

Fields

kind

kind : KindSource

What went wrong.

path

path : StringSource

The path the program supplied, or stdin, stdout, or stderr for a standard stream.

message

message : StringSource

A stable reason for a known kind, or the system’s message for Other.

Instances:

Eq Error
Show Error

Kind

type Kind    = NotFound    | PermissionDenied    | AlreadyExists    | IsDirectory    | NotDirectory    | OtherSource

The kinds of operating-system failure a program can act on. Anything else is Other, with the system’s own text in the error’s message. Match on the kind for behaviour that is the same on every platform.

Constructors

NotFound

NotFound : KindSource

The path does not exist.

PermissionDenied

PermissionDenied : KindSource

The program may not access the path.

AlreadyExists

AlreadyExists : KindSource

Something already exists at the path.

IsDirectory

IsDirectory : KindSource

The path is a directory where a file was expected.

NotDirectory

NotDirectory : KindSource

A path component is not a directory.

Other

Other : KindSource

Any other failure.

Instances:

Eq Kind
Show Kind

Line

type Line =    { text : String    , ending : String    }Source

One line of input and the exact terminator that ended it.

Fields

text

text : StringSource

The line without its terminator.

ending

ending : StringSource

"\n", "\r\n", or "" for an unterminated final line.

Instances:

Eq Line
Show Line

IO

effect IOSource

Interaction with the world outside the program. It has no operations of its own: natives perform it, and only main and the interpreter can run it.

describeError

describeError : Error -> StringSource

The failure as path: reason. Known kinds use stable text rather than the system’s, so they read the same on every platform; Other shows the system message.

import IO exposing (Kind(..))

IO.describeError { kind = NotFound, path = "a.txt", message = "" } == "a.txt: no such file or directory"
IO.describeError { kind = Other, path = "b", message = "device busy" } == "b: device busy"

lineEnding

lineEnding : String -> StringSource

A raw line’s terminator: "\n", "\r\n", or "".

import IO

IO.lineEnding "abc\r\n" == "\r\n"
IO.lineEnding "abc" == ""

lineText

lineText : String -> StringSource

A raw line without its terminator, as readLine splits it.

import IO

IO.lineText "abc\r\n" == "abc"
IO.lineText "abc" == "abc"