Initial commit
This commit is contained in:
commit
c101616e62
309 changed files with 53937 additions and 0 deletions
36
bundled/Basement/MutableBuilder.hs
Normal file
36
bundled/Basement/MutableBuilder.hs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{-# LANGUAGE BangPatterns #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE RebindableSyntax #-}
|
||||
{-# LANGUAGE NoImplicitPrelude #-}
|
||||
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
||||
module Basement.MutableBuilder
|
||||
( Builder(..)
|
||||
, BuildingState(..)
|
||||
) where
|
||||
|
||||
import Basement.Compat.Base
|
||||
import Basement.Compat.MonadTrans
|
||||
import Basement.Types.OffsetSize
|
||||
import Basement.Monad
|
||||
|
||||
newtype Builder collection mutCollection step state err a = Builder
|
||||
{ runBuilder :: State (Offset step, BuildingState collection mutCollection step (PrimState state), Maybe err) state a }
|
||||
deriving (Functor, Applicative, Monad)
|
||||
|
||||
-- | The in-progress state of a building operation.
|
||||
--
|
||||
-- The previous buffers are in reverse order, and
|
||||
-- this contains the current buffer and the state of
|
||||
-- progress packing the elements inside.
|
||||
data BuildingState collection mutCollection step state = BuildingState
|
||||
{ prevChunks :: [collection]
|
||||
, prevChunksSize :: !(CountOf step)
|
||||
, curChunk :: mutCollection state
|
||||
, chunkSize :: !(CountOf step)
|
||||
}
|
||||
|
||||
instance Monad state => MonadFailure (Builder collection mutCollection step state err) where
|
||||
type Failure (Builder collection mutCollection step state err) = err
|
||||
mFail builderError = Builder $ State $ \(offset, bs, _) ->
|
||||
return ((), (offset, bs, Just builderError))
|
||||
Loading…
Add table
Add a link
Reference in a new issue