unboxed-references: A library for reference cells backed by unboxed-vectors

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

This package contains an interface to references backed by unboxed vectors

For an example of how to use it:

  module Main where

  import           Data.STRef.Unboxed
  import           Control.Monad.ST

  main :: IO ()
  main =
    do
      print counter
      print mySum
      print strictModify

  -- |
  -- Runs a for loop each time modifying the reference cell to add
  -- one.
  counter :: Int
  counter =
   runST $
     do
       ref <- newSTRefU 0
       for_ [1..100] $ modifySTRefU ref (+ 1)
       readSTRefU ref
  -- |
  -- Runs a for loop to add all the numbers between 1 and 10.
  mySum :: Int
  mySum =
    runST $
      do
        ref <- newSTRefU 0
        for_ [1..10] $ \i -> modifySTRefU ref (+ i)
        readSTRefU ref
  -- |
  -- This shows that modifySTRefU is strict in its argument.
  strictModify :: Int
  strictModify =
    runST $
      do
        ref <- newSTRefU 0
        modifySTRefU ref (\_ -> Unsafe.unsafePerformIO $ print "Got here!" >> pure 10)
        writeSTRefU ref 42
         readSTRefU ref

This gives the following:

> main
100
55
"Got here!"
42

Properties

Versions 0.1.0, 0.1.0
Change log CHANGELOG.md
Dependencies base (>=4.12.0.0 && <4.14), unboxed-references, vector (>=0.12.0 && <0.13) [details]
License BSD-3-Clause
Copyright 2019
Author Callan McGill
Maintainer callan.mcgill@gmail.com
Category Data
Home page https://github.com/Boarders/unboxed-references
Bug tracker https://github.com/Boarders/unboxed-references/issues
Source repo head: git clone https://github.com/Boarders/unboxed-references
Uploaded by callanmcgill at 2019-12-15T22:52:24Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees