Skip to content

Add Handle type with scope parameter #43

@yaitskov

Description

@yaitskov

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.

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

haskell/bytestring#708

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions