-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Ivory standard library. -- -- A standard library for Ivory. @package ivory-stdlib @version 0.1.0.3 module Ivory.Stdlib.String -- | Ivory module definition. stdlibStringModule :: Module -- | String initialization. Error returned if the String is too -- large. stringInit :: IvoryString str => String -> Init str -- | Compare strings (of possibly different types) for equality. Returns -- true if the strings are the same length and contain the same bytes. istr_eq :: (IvoryString str1, IvoryString str2) => ConstRef s1 str1 -> ConstRef s2 str2 -> Ivory eff IBool -- | Copy an Ivory string to a fixed-size, null-terminated C string. The -- destination string is always properly terminated, but may be truncated -- if the buffer is too small. -- -- FIXME: This should return false if the string was truncated. sz_from_istr :: (ANat len, IvoryString str) => Ref s1 (Array len (Stored Uint8)) -> ConstRef s2 str -> Ivory eff () -- | Return the length of a string. istr_len :: IvoryString str => ConstRef s str -> Ivory eff Len -- | Copy the contents of a fixed-size C string into an Ivory string. If -- the source string is not null terminated (and therefore corrupt), this -- will copy no more than len characters. -- -- FIXME: This should return false if the string was truncated. istr_from_sz :: (ANat len, IvoryString str) => Ref s1 str -> ConstRef s2 (Array len (Stored Uint8)) -> Ivory eff () -- | Copy one string into another of the same type. istr_copy :: IvoryString str => Ref s1 str -> ConstRef s2 str -> Ivory eff () -- | Store a constant string into an IvoryString. Error returned if -- the String is too large. string_lit_store :: IvoryString str => String -> Ref s str -> Ivory eff () stdlibStringArtifacts :: [Located Artifact] -- | Copy a Haskell string directly to an array of uint8s. string_lit_array :: ANat n => String -> Ref s (Array n (Stored Uint8)) -> Ivory eff () module Ivory.Stdlib.Operators -- | Infix structure field access and dereference. This is a shorthand for -- 'deref $ s~>x'. (~>*) :: (IvoryVar a, IvoryStruct sym, IvoryRef ref, IvoryStore a, IvoryExpr (ref s (Stored a)), IvoryExpr (ref s (Struct sym))) => ref s (Struct sym) -> Label sym (Stored a) -> Ivory eff a -- | Modify the value stored at a reference by a function. (%=) :: IvoryStore a => Ref s (Stored a) -> (a -> a) -> Ivory eff () -- | Modify the value stored at a reference by a function that returns a -- value in the Ivory monad (%=!) :: IvoryStore a => Ref s (Stored a) -> (a -> Ivory eff a) -> Ivory eff () -- | Increment the value stored at a reference. (+=) :: (Num a, IvoryStore a) => Ref s (Stored a) -> a -> Ivory eff () -- | This module provides an interface for a nullable Ivory type. -- -- To define a type like Haskell's Maybe Float, define an Ivory -- structure type, and make the structure an instance of -- MaybeType. -- --
-- [ivory|
-- struct maybe_float
-- { mf_valid :: Stored IBool
-- ; mf_value :: Stored IFloat
-- }
-- |]
--
-- instance MaybeType "maybe_float" IFloat where
-- maybeValidLabel = mf_valid
-- maybeValueLabel = mf_value
--
--
-- With this definition in place, any of the functions in this module
-- will accept a Struct "maybe_float".
--
-- These structure types must be defined in an Ivory module as usual, and
-- it is recommended to make them private unless they are necessary as
-- part of the module's public interface.
module Ivory.Stdlib.Maybe
class (IvoryStruct sym, IvoryExpr t, IvoryStore t, IvoryInit t) => MaybeType (sym :: Symbol) t | sym -> t
-- | Return a boolean field indicating whether the value is valid.
maybeValidLabel :: MaybeType sym t => Label sym (Stored IBool)
-- | Return the field containing a value, if it is valid.
maybeValueLabel :: MaybeType sym t => Label sym (Stored t)
-- | Return an initializer for a maybe type with a valid value.
initJust :: MaybeType sym a => a -> Init (Struct sym)
-- | Return an initializer for a maybe type with no value.
initNothing :: MaybeType sym a => Init (Struct sym)
-- | Retrieve a maybe's value given a default if it is nothing.
getMaybe :: MaybeType sym a => ConstRef s1 (Struct sym) -> a -> Ivory eff a
-- | Set a maybe value to a valid value.
setJust :: MaybeType sym a => Ref s1 (Struct sym) -> a -> Ivory eff ()
-- | Set a maybe value to an invalid value.
setNothing :: MaybeType sym a => Ref s1 (Struct sym) -> Ivory eff ()
-- | Set a maybe's value to a default if it is nothing, returning the
-- current value.
setDefault :: MaybeType sym a => Ref s1 (Struct sym) -> a -> Ivory eff a
-- | Set a maybe's value to a default value if it is nothing.
setDefault_ :: MaybeType sym a => Ref s1 (Struct sym) -> a -> Ivory eff ()
-- | Modify a maybe value by an expression if it is not nothing.
mapMaybe :: MaybeType sym a => (a -> a) -> Ref s1 (Struct sym) -> Ivory eff ()
-- | Modify a maybe value by an action if it is not nothing.
mapMaybeM :: MaybeType sym a => (a -> Ivory eff a) -> Ref s1 (Struct sym) -> Ivory eff ()
-- | Call an action with a maybe value if it is not nothing.
mapMaybeM_ :: MaybeType sym a => (a -> Ivory eff ()) -> Ref s1 (Struct sym) -> Ivory eff ()
-- | Flipped version of mapMaybeM.
forMaybeM :: MaybeType sym a => Ref s1 (Struct sym) -> (a -> Ivory eff a) -> Ivory eff ()
-- | Flipped version of mapMaybeM_.
forMaybeM_ :: MaybeType sym a => Ref s1 (Struct sym) -> (a -> Ivory eff ()) -> Ivory eff ()
module Ivory.Stdlib.Init
-- | Variant of izero that constrains the length of the array to
-- match a given type-level natural. This reduces the need for the
-- ScopedTypeVariables extension in Ivory code.
izerolen :: (IvoryArea area, IvoryZero area, ANat bound) => Proxy bound -> Init (Array bound area)
-- | Variant of iarray that constrains the length of the array to
-- match a given type-level natural. This reduces the need for the
-- ScopedTypeVariables extension in Ivory code.
iarraylen :: (IvoryArea area, IvoryZero area, ANat bound) => Proxy bound -> [Init area] -> Init (Array bound area)
module Ivory.Stdlib.Control
ifte :: (IvoryStore a, IvoryZero (Stored a), GetAlloc eff ~ Scope s) => IBool -> Ivory eff a -> Ivory eff a -> Ivory eff a
when :: IBool -> Ivory eff () -> Ivory eff ()
unless :: IBool -> Ivory eff () -> Ivory eff ()
-- | A multi-way if. This is useful for avoiding an explosion of nesting
-- and parentheses in complex conditionals.
--
-- Instead of writing nested chains of ifs:
--
-- -- ifte_ (x >? 100) -- (store result 10) -- (ifte_ (x >? 50) -- (store result 5) -- (ifte_ (x >? 0) -- (store result 1) -- (store result 0))) ---- -- You can write: -- --
-- cond_ -- [ x >? 100 ==> store result 10 -- , x >? 50 ==> store result 5 -- , x >? 0 ==> store result 1 -- , true ==> store result 0 -- ] ---- -- Note that "==>" is non-associative and has precedence 0, so you -- will need parentheses to call functions with "$" on the left-hand -- side: -- --
-- cond_ [ (f $ g x) ==> y ] ---- -- rather than: -- --
-- cond_ [ f $ g x ==> y ] --cond_ :: [Cond eff ()] -> Ivory eff () cond :: (IvoryStore a, IvoryZero (Stored a), GetAlloc eff ~ Scope s) => [Cond eff a] -> Ivory eff a (==>) :: IBool -> Ivory eff a -> Cond eff a data Cond eff a module Ivory.Stdlib.Memory -- | handy shorthand for transfering members resultInto :: IvoryStore a => Ivory eff a -> Ref s (Stored a) -> Ivory eff () into :: IvoryStore a => Ref s (Stored a) -> Ref s' (Stored a) -> Ivory eff () -- | Copies a prefix of an array into a postfix of another array. That is, -- copy from array from (either a Ref or a -- ConstRef) into array to starting at index -- toOffset in to. Copying continues until either the -- from array is fully copied, the to array is full, or index -- end in the from array is reached (index end -- is not copied). to copy the full from array, let end -- equal 'arrayLen from'. arrayCopy :: (ANat n, ANat m, IvoryRef r, IvoryExpr (r s2 (Array m (Stored t))), IvoryExpr (r s2 (Stored t)), IvoryStore t) => Ref s1 (Array n (Stored t)) -> r s2 (Array m (Stored t)) -> Sint32 -> Sint32 -> Ivory eff () module Ivory.Stdlib stdlibModules :: [Module]