Skip to content

HuwCampbell/haskell-list-builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Haskell List Builder

Extra unsafe sequencing of IO actions from Twan van Laarhoven packaged up, along with unfoldIO and an implementation of Scala's List Buffer. This means we can have tail recursive sequence and traverse specialised for lists of IO actions.

For algorithms which are more easily written in a mutable way we have ListBuilder s a. A ListBuilder s a is like a wrapper around an ST s [a], but with a constant time append as well as prepend.

Basic usage:

import qualified Data.ListBuilder as ListBuilder

palindrome :: [a] -> [a]
palindrome xs = runST $ do
  bldr <- ListBuilder.newBuilder
  for_ xs $ \x -> do
    ListBuilder.prepend x bldr
    ListBuilder.append x bldr
  ListBuilder.unsafeFreeze bldr

Other functions of interest:

traverseIO :: (a -> IO b) -> [a] -> IO [b]
sequenceIO :: [IO a] -> IO [a]
unfoldIO :: IO (Maybe a) -> IO [a]

About

Mutable List Builders in Haskell

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published