linear-base-0.5.0: Standard library for linear types.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Simple.FileIO

Description

We implement a function that prints the first line of a file.

We do this with the normal file IO interface in base and the linear file IO interface in linear-base. With the latter, the protocol for using files is enforced by the linear type system. For instance, forgetting to close the file will induce a type error at compile time. That is, typechecking proves that all opened files are closed at some later point in execution. With the former interface, we have code that type checks but will error or cause errors at runtime.

Synopsis

Non-linear first line printing

Linear first line printing

Linear and non-linear combinators

type RIO = RIO Source #

(>>#=) :: RIO a %1 -> (a %1 -> RIO b) %1 -> RIO b infixl 1 Source #

Linear bind Notice the continuation has a linear arrow, i.e., (a %1-> RIO b)

(>>==) :: RIO () %1 -> (() -> RIO b) %1 -> RIO b infixl 1 Source #

Non-linear bind Notice the continuation has a non-linear arrow, i.e., (() -> RIO b). For simplicity, we don't use a more general type, like the following: (>>==) :: RIO (Ur a) %1-> (a -> RIO b) %1-> RIO b

inject :: a %1 -> RIO a Source #

Inject provided just to make the type explicit

The explicit example