haskell / haskell/primitive

IO operations for bytearray

Open
#299 6 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Haskell
Stars
123
Forks
60
PR merge metrics
No merged PRs in 30d

Description

Often one wants to use `ByteArray` over a `ByteString` but you have to implement all of the `IO` operations yourself (with a good chance for shooting yourself in the foot). I think it would be better if the library provided such operations e.g. taking the operations from `ByteString`

```haskell
getLine :: IO ByteArray

getContents :: IO ByteArray

putStr :: ByteArray -> IO ()

interact :: (ByteArray -> ByteArray) -> IO ()

readFile :: FilePath -> IO ByteArray

writeFile :: FilePath -> ByteArray -> IO ()

appendFile :: FilePath -> ByteArray -> IO ()

hGetLine :: Handle -> IO ByteArray

hGetContents :: Handle -> IO ByteArray

hGet :: Handle -> Int -> IO ByteArray

hGetSome :: Handle -> Int -> IO ByteArray

hGetNonBlocking :: Handle -> Int -> IO ByteArray

hPut :: Handle -> ByteArray -> IO ()

hPutNonBlocking :: Handle -> ByteArray -> IO ByteArray

hPutStr :: Handle -> Byte\Array -> IO ()
```

I realise there are longstanding debates the remit of the `primitive` library and if this is not the place for it then I think it would be worthwhile for the CLC to declare a place for such utilities. This would give people more of a choice over whether to use `ByteArray` vs `ByteString` vs `Vector` without having to re-implement basics every time (or try to find others who have).

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.