haskell / haskell/file-io

Add Handle type with scope parameter

Open
#43 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
25
Forks
11
PR merge metrics
No merged PRs in 30d

Description

`withBinaryFile` and `openBinaryFile` produce Handle values with different semantic and they should live in different types, e.g. using `hClose` on Handle from `withBinaryFile` is a runtime error.

```haskell

data Scope = With | Free deriving (Show, Eq)

newtype Handle (s :: Scope) = Handle IO.Handle deriving (Show, Eq)

hClose :: Handle Free -> IO ()
hClose (Handle h) = IO.hClose h

mkFreeHandle :: IO.Handle -> Handle Free
mkFreeHandle = Handle

openBinaryFile :: OsPath -> IOMode -> IO (Handle Free)
withBinaryFile :: NFData r => OsPath -> IOMode -> (Handle With -> IO r) -> IO r
```

https://github.com/haskell/bytestring/pull/708

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.