waterfall-cad-0.2.2.0: Declarative CAD/Solid Modeling Library
Safe HaskellNone
LanguageHaskell2010

Waterfall.Internal.Finalizers

Description

These functions exist because the underlying `opencascade-hs` library, makes heavy use of Acquire from resourcet to handle memory management. However `waterfall-cad` does not (at the highest level) keep values in the Acquire monad. (This is required to support functions like volume, which return pure Haskell primitives.)

Synopsis

Documentation

unsafeFromAcquire :: Acquire a -> a Source #

Converting to a value in the Acquire monad, to a raw value. Analagous to calling unsafePerformIO to extract a value in the IO monad. The same constraints as apply to unsafePerformIO apply to this method. That is, it should only be used on "philosophically pure" actions.

The free action of the resource is called when the underlying value goes out of scope of the Haskell garbage collection, so may run at an unpredictable time.

fromAcquire :: Acquire a -> IO a Source #

Convert a resource in the Acquire monad to a value in IO the free action of the resource is called when the underlying value goes out of scope of the Haskell garbage collection so may run at an unpredictable time.

fromAcquireMay :: Acquire (Maybe a) -> IO (Maybe a) Source #

variant of fromAcquire which registers the finalizer on the _value_ in a Maybe as opposed to the maybe itself this is useful for wrapping IO actions that return the type `IO (Maybe a)` where the Maybe will often be finalized well before the value

toAcquire :: a -> Acquire a Source #

Add a pure value (which may or may not have been generated by unsafeFromAcquire) back into the Acquire monad. Using this action _should_ prevent the underlying value from going out of GC scope untill the resource is freed.