hs-php-session-0.0.9.3: PHP session and values serialization

Portabilityportable
Stabilityexperimental
MaintainerEdward L. Blake <edwardlblake@gmail.com>
Safe HaskellSafe-Inferred

Data.PHPSession.ImplicitConv.ConvBool

Contents

Description

Non-coerced and coerced rule sets for converting PHPSessionValue objects to Bool.

Synopsis

Non-coerced from PHPSessionValue

boolDefaultFalseFrom :: PHPSessionValue -> BoolSource

Returns the value of a boolean value as a Bool, or returns False as the default Bool value if the PHPSessionValue is not a boolean type. This function is similar to the "strict comparison" operator against the boolean TRUE value.

boolDefaultTrueFrom :: PHPSessionValue -> BoolSource

Returns the value of a boolean value as a Bool, or returns True as the default Bool value if the PHPSessionValue is not a boolean type.

Type coercion from PHPSessionValue

boolFromPHPLooseComparisonWithTrue :: PHPSessionValue -> BoolSource

Coerces a PHPSessionValue to a Bool based on PHP's conversion rules to convert arbitrary values to boolean for evaluation. This function's behaviour is also reminiscent of PHP's "loose comparison" operator against boolean TRUE. http://php.net/manual/language.types.boolean.php

Values that result in True are TRUE, non-zero numbers, non-empty strings other than "0", objects, and non-empty arrays.

A conversion documented in the PHP manual involving SimpleXML objects that coerce to FALSE instead of TRUE when created with empty tags is not implemented by this function, as SimpleXML objects cannot be serialized directly and so don't have a valid serializable form to convert from in any case.

Because of the range of valid values of the "loose comparison" operator, this function and variations based on other dynamically typed languages is provided mainly for circumstances where they may be the best fit to map particular data values to a boolean truth value system. boolFromReducedLooseCoercionSafe provides a significantly reduced subset of valid values to coerce from for the purpose of determining a "confirmation" value, as opposed to simply determining if a value exists or not.

boolFromPHPLooseComparisonWithTrueNullable :: PHPSessionValue -> Maybe BoolSource

A version of boolFromPHPLooseComparisonWithTrue where NULL returns Nothing and all other inputs returns Just with the boolean result.

boolFromReducedLooseCoercionSafe :: PHPSessionValue -> Either String BoolSource

Coerces a PHPSessionValue to a Bool through a reduced subset of valid values. boolFromReducedLooseCoercionSafe and boolFromReducedLooseCoercion are functions intended for testing a variable for a boolean "confirmation" from a limited number of probable representations.

Values that result in True are TRUE, non-zero numbers, "1" and "-1".

Values that result in False are FALSE, zero numbers, NULL, "0" and "".

Values such as arrays, objects and arbitrary strings, are invalid with this function and return an error. In the case of boolFromReducedLooseCoercionSafe this returns a Left with the error message.

boolFromReducedLooseCoercionNullableSafe :: PHPSessionValue -> Either String (Maybe Bool)Source

A version of boolFromReducedLooseCoercionSafe where NULL returns Right Nothing and all other inputs returns Right Just with the boolean result. May return Left with an error message if given invalid values.

boolFromReducedLooseCoercionNullable :: PHPSessionValue -> Maybe BoolSource

A version of boolFromReducedLooseCoercion where NULL returns Nothing and all other inputs returns Just with the boolean result. May throw an exception on invalid values.

boolFromESBooleanCoercionRules :: PHPSessionValue -> BoolSource

Alternative boolean coercion based on the JS/ES boolean conversion rules. A particular distinction of the coercion behaviour of this function compared to the behaviour of other functions is that floating point NaN returns False instead of True. Values that return False are NAN, 0, the empty string "", NULL and FALSE

PHP objects, arrays and objects implementing Serializable always return True.

JS/ES's boolean conversion is described in section 9.2 of the ECMA 262 standard.

boolFromPerlBooleanCoercionRules :: PHPSessionValue -> BoolSource

Alternative boolean coercion based on non-overloaded Perl 5 rules. Values that return False are the empty string "", the string containing "0", 0, NULL and FALSE.

PHP objects, arrays and objects implementing Serializable always return True.

Perl's boolean coercion rules are described in the section "Truth and Falsehood" of "perlsyn". http://perldoc.perl.org/perlsyn.html#Truth-and-Falsehood

boolFromPythonBooleanCoercionRules :: PHPSessionValue -> BoolSource

Alternative boolean coercion based on non-overloaded Python rules. Values that return False are the empty array [], the empty string "", 0, NULL and FALSE.

PHP objects and objects implementing Serializable always return True.

Python's boolean conversion rules are described in "Truth Value Testing" in section 3.1 of Python 2.5's Library Reference. https://docs.python.org/release/2.5.2/lib/truth.html

boolFromLuaBooleanCoercionRules :: PHPSessionValue -> BoolSource

Alternative boolean coercion based on Lua rules, all values are True except NULL and FALSE.

For Lua's conversion rules, refer to the passage in section 2.4.4 "Control Structures" of Lua 5.1's Manual. http://www.lua.org/manual/5.1/manual.html