Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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
- printFirstLine :: FilePath -> IO ()
- printFirstLineNoClose :: FilePath -> IO ()
- printFirstLineAfterClose :: FilePath -> IO ()
- linearGetFirstLine :: FilePath -> RIO (Ur Text)
- linearPrintFirstLine :: FilePath -> IO ()
- type RIO = RIO
- type LinHandle = Handle
- (>>#=) :: RIO a %1 -> (a %1 -> RIO b) %1 -> RIO b
- (>>==) :: RIO () %1 -> (() -> RIO b) %1 -> RIO b
- inject :: a %1 -> RIO a
- getFirstLineExplicit :: FilePath -> RIO (Ur Text)
- printFirstLineExplicit :: FilePath -> IO ()
Non-linear first line printing
printFirstLine :: FilePath -> IO () Source #
printFirstLineNoClose :: FilePath -> IO () Source #
printFirstLineAfterClose :: FilePath -> IO () Source #
Linear first line printing
linearPrintFirstLine :: FilePath -> IO () Source #
Linear and non-linear combinators
(>>#=) :: 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
The explicit example
printFirstLineExplicit :: FilePath -> IO () Source #