Portability | portable |
---|---|
Stability | experimental |
Maintainer | Edward L. Blake <edwardlblake@gmail.com> |
Safe Haskell | Safe-Inferred |
Non-coerced translation between PHPSessionValue
and various Haskell types.
convTo
provide convenient translation from native types to PHPSessionValue
,
while translation from PHPSessionValue
to native types is provided through
convFrom
and convFromSafe
.
- convTo :: ConversionToPHPValue a => a -> PHPSessionValue
- convFrom :: ConversionFromPHPValueOrMismatch b => PHPSessionValue -> b
- convFromSafe :: ConversionFromPHPValueOrMismatch b => PHPSessionValue -> Either String b
- class ConversionToPHPValue a where
- convTo' :: a -> PHPSessionValue
- class ConversionFromPHPValueOrMismatch b where
- convFromOM :: PHPSessionValue -> Either String b
Convert to PHPSessionValue
convTo :: ConversionToPHPValue a => a -> PHPSessionValueSource
convTo
is a convenience function that converts natively typed
values to PHPSessionValue
, with the resulting PHP type determined
by the type cast or inferred.
arrayOfPHPStrings :: PHPSessionValue arrayOfPHPStrings = let str1 = "Hello" :: BS.ByteString str2 = "World" in convTo [(0 :: Int, str1), (1, str2)]
In the above example code, the OverloadedStrings
language extension is assumed.
Convert from PHPSessionValue
convFrom :: ConversionFromPHPValueOrMismatch b => PHPSessionValue -> bSource
convFrom
and convFromSafe
are convenience functions that translate PHP
values stored as PHPSessionValue
into appropriate Haskell types depending on
the desired type cast or inferred. Functions provided in this module provide
non-coerced type translations and so will either carry on the translation or
signal the fact that the attempted conversion will alter the type of the
value. For situations where altering value types is expected, alternative
conversion functions with similar type signatures are provided in modules
within Data.PHPSession.ImplicitConv.
The example arrayOfPHPStrings definition given in convTo
can be reverted back
to Haskell types, which evaluates to [(0,"Hello"),(1,"World")]
.
>>>
convFrom arrayOfPHPStrings :: [(Int,LBS.ByteString)]
[(0,"Hello"),(1,"World")]
However, if the desired type signature is changed to a completely different type, then a runtime exception is thrown:
>>>
convFrom arrayOfPHPStrings :: [(Int,Int)]
*** Exception: Type mismatch converting from (PHPSessionValueString "Hello") to Int
Where there is the possibility that the value being sought may be NULL
, the
type should be (
.
Maybe
a)
convFromSafe :: ConversionFromPHPValueOrMismatch b => PHPSessionValue -> Either String bSource
A version of convFrom
which returns a Left
with an error message instead
of throwing an exception.
Type classes
class ConversionToPHPValue a whereSource
convTo' :: a -> PHPSessionValueSource
ConversionToPHPValue Bool | |
ConversionToPHPValue Double | |
ConversionToPHPValue Int | |
ConversionToPHPValue Int32 | |
ConversionToPHPValue Int64 | |
ConversionToPHPValue ByteString | |
ConversionToPHPValue ByteString | |
ConversionToPHPValue PHPSessionValue | |
(ConversionToPHPValue a, ConversionToPHPValue b) => ConversionToPHPValue [(a, b)] | |
ConversionToPHPValue [(PHPSessionValue, PHPSessionValue)] | |
ConversionToPHPValue a => ConversionToPHPValue (Maybe a) | |
ConversionToPHPValue (PHPSessionClassName, [(PHPSessionValue, PHPSessionValue)]) | |
ConversionToPHPValue (PHPSessionClassName, ByteString) |
class ConversionFromPHPValueOrMismatch b whereSource
convFromOM :: PHPSessionValue -> Either String bSource