Instances2Consumable, Dupable
Consumable PoolDefined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalDupable PoolDefined in linear-base-0.4.0 · Foreign.Marshal.Pure.Internal
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05
Modulelinear-base-0.4.0Haskell2010
This module introduces primitives to safely allocate and discard system heap memory (not GC heap memory) for storing values explicitly. (Basically, a haskell program has a GC that at runtime, manages its own heap by freeing and allocating space from the system heap.) Values discarded explicitly don't need to be managed by the garbage collector (GC), which therefore has less work to do. Less work for the GC can sometimes mean more predictable request latencies in multi-threaded and distributed applications.
This module is meant to be imported qualified.
Run a computation that uses heap memory by passing a continuation to
withPool of type Pool %1-> Ur b. Allocate and free with
alloc and deconstruct. Make as many or as few pools you need, by
using the Dupable and Consumable instances of Pool.
A toy example:
:set -XLinearTypesimport Preludeimport Data.Unrestricted.Linearimport qualified Foreign.Marshal.Pure as Manual:{ nothingWith3 :: Pool %1-> Ur Int nothingWith3 pool = move (Manual.deconstruct (Manual.alloc 3 pool)):}
unur (Manual.withPool nothingWith3)3
Pools are memory pools from which a user can safely allocate and use heap memory manually by passing withPool a continuation. An alternative design would have allowed passing continuations to allocation functions but this could break tail-recursion in certain cases.
Pools play another role: resilience to exceptions. If an exception is raised, all the data in the pool is deallocated.
Note that data from one pool can refer to data in another pool and vice versa.
You can find example data structure implementations in Foreign.List and
Foreign.Heap here.
Consumable PoolDefined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalDupable PoolDefined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalGiven a linear computation that manages memory, run that computation.
'Box a' is the abstract type of manually managed data. It can be used as
part of data type definitions in order to store linked data structure off
heap. See Foreign.List and Foreign.Pair in the examples directory of
the source repository.
Storable (Box a)Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalKnownRepresentable (Box a)Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalRepresentable (Box a)Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.Internaltype AsKnown (Box a) = Box aDefined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalStore a value a on the system heap that is not managed by the GC.
Retrieve the value stored on system heap memory.
This abstract type class represents values natively known to have a GC-less implementation. Basically, these are sequences (represented as tuples) of base types.
KnownRepresentable IntDefined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalKnownRepresentable WordDefined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalKnownRepresentable ()Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalKnownRepresentable (Ptr a)Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalKnownRepresentable (Box a)Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalKnownRepresentable a => KnownRepresentable (Maybe a)Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalKnownRepresentable a => KnownRepresentable (Ur a)Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.Internal(KnownRepresentable a, KnownRepresentable b) => KnownRepresentable (a, b)Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.Internal(KnownRepresentable a, KnownRepresentable b, KnownRepresentable c) => KnownRepresentable (a, b, c)Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalLaws of Representable:
type family AsKnown aRepresentable IntDefined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalRepresentable WordDefined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalRepresentable ()Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalRepresentable (Ptr a)Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalRepresentable (Box a)Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalRepresentable a => Representable (Maybe a)Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.Internal(Representable a, Representable b) => Representable (a, b)Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.Internal(Representable a, Representable b, Representable c) => Representable (a, b, c)Defined in linear-base-0.4.0 · Foreign.Marshal.Pure.InternalThis is an easier way to create an instance of Representable. It is a bit abusive to use a type class for this (after all, it almost never makes sense to use this as a constraint). But it works in practice.
To use, define an instance of MkRepresentable myType intermediateType
then declare the following instance:
instance Representable myType where {type AsKnown = AsKnown intermediateType}And the default instance mechanism will create the appropriate Representable instance.
Laws of MkRepresentable: