Packages

The Phi Programming Language

Current section

Files

Jump to
phi stdlib Data Term Persistent.phi
Raw

stdlib/Data/Term/Persistent.phi

-----------------------------------------------------------------------------
-- |
-- Module : Data.Term.Persistent
-- Copyright : (c) 2020-2021 EMQ Technologies Co., Ltd.
-- License : BSD-style (see the LICENSE file)
--
-- Maintainer : Feng Lee, feng@emqx.io
-- Yang M, yangm@emqx.io
-- Stability : experimental
-- Portability : portable
--
-- The Persistent Terms module.
--
-----------------------------------------------------------------------------
module Data.Term.Persistent where
import Control.Monad (IO)
import Data.Unit (Unit)
import Foreign (ffiIO0, ffiIO1, ffiIO2)
type PersistentTermInfo =
{ count :: Integer
-- ^ The number of persistent terms.
, memory :: Integer
-- ^ The total amount of memory (measured in bytes) used by all persistent terms.
}
-- | Erase the name for the persistent term with key Key.
erase :: forall k. k -> IO Boolean
erase = ffiIO1 :persistent_term :erase
-- | Retrieve the value for the persistent term associated with the key Key.
get :: forall k v. k -> IO v
get = ffiIO1 :persistent_term :get
-- | Retrieve the value for the persistent term associated with the key Key.
-- Return Default if no term has been stored with the key Key.
getWithDefault :: forall k d v. k -> d -> IO v
getWithDefault = ffiIO2 :persistent_term :get
-- TODO: | Retrieve the keys and values for all persistent terms.
-- getAll :: forall k v. IO (List (k, v))
-- getAll = ffiIO0 "persistent_term" "get"
-- | Return information about persistent terms.
info :: IO PersistentTermInfo
info = ffiIO0 :persistent_term :info
put :: forall k v. k -> v -> IO ()
put = ffiIO2 :persistent_term :put