MIT licensed by Michael Snoyman
Maintained by [email protected]
This version can be pinned in stack with:say-0.1.0.1@sha256:f20554ed3bcc198965a934385fbd98f9fd9754705f06eb2ee2b13a9b2c530632,1822

Module documentation for 0.1.0.1

Used by 3 packages in nightly-2024-10-21(full list with versions):

say

Send textual messages to a Handle in a thread-friendly way.

Build Status Build status

The motivation for this package is described in a blog post on Haskell’s Missing Concurrency Basics. The simple explanation is, when writing a line of textual data to a Handle - such as sending some messages t o ther terminal - we’d like to have the following properties:

  • Properly handle character encoding settings on the Handle
  • For reasonably sized messages, ensure that the entire message is written in one chunk to avoid interleaving data with other threads
    • This includes the trailing newline character
  • Avoid unnecessary memory allocations and copies
  • Minimize locking
  • Provide a simple API

On the last point: for the most part, you can make the following substitutions in your API usage:

  • Replace putStrLn with say
  • Replace print with sayShow
  • If you’re using a String instead of Text, replace putStrLn with sayString

In addition, sayErr, sayErrString and sayErrShow work on standard error instead, and hSay, hSayString and hSayShow work on arbitrary Handles.

#!/usr/bin/env stack
-- stack --install-ghc --resolver lts-6.23 runghc --package async --package say
import Control.Concurrent.Async (mapConcurrently)
import Control.Monad            (forM_, void)
import Say                      (sayString)

worker :: Int -> IO ()
worker ident = forM_ [1..1000] $ \msg -> sayString $ concat
    [ "Hello, I am worker #"
    , show ident
    , ", and this is message #"
    , show msg
    ]

main :: IO ()
main = void $ mapConcurrently worker [1..100]

Changes

say package

0.1.0.1

  • Doc updates
  • Version bound updates
  • hpack-ified

0.1.0.0

  • Initial commit