Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- class ToPy a where
- toPy :: a -> IO SomeObject
- class FromPy a where
- fromPy :: SomeObject -> IO a
- data PyCastException = PyCastException String
- easyToPy :: Object p => (h -> IO p) -> h -> IO SomeObject
- easyFromPy :: (Concrete p, Typeable h) => (p -> IO h) -> Proxy h -> SomeObject -> IO h
Documentation
ToPy
instances indicate that a type can be marshalled from Haskell to Python automatically
For example, ToPy Integer
indicates that we know how to take a Haskell Integer
and convert
it into a Python int
object
toPy :: a -> IO SomeObject Source #
Instances
ToPy Text Source # | |
Defined in CPython.Simple.Instances | |
ToPy String Source # | |
Defined in CPython.Simple.Instances | |
ToPy Integer Source # | |
Defined in CPython.Simple.Instances | |
ToPy Bool Source # | |
Defined in CPython.Simple.Instances | |
ToPy Char Source # | |
Defined in CPython.Simple.Instances | |
ToPy Double Source # | |
Defined in CPython.Simple.Instances | |
ToPy a => ToPy (Maybe a) Source # | |
Defined in CPython.Simple.Instances | |
ToPy a => ToPy [a] Source # | |
Defined in CPython.Simple.Instances toPy :: [a] -> IO SomeObject Source # | |
(ToPy a, ToPy b) => ToPy (a, b) Source # | |
Defined in CPython.Simple.Instances toPy :: (a, b) -> IO SomeObject Source # | |
(ToPy a, ToPy b, ToPy c) => ToPy (a, b, c) Source # | |
Defined in CPython.Simple.Instances toPy :: (a, b, c) -> IO SomeObject Source # | |
(ToPy a, ToPy b, ToPy c, ToPy d) => ToPy (a, b, c, d) Source # | |
Defined in CPython.Simple.Instances toPy :: (a, b, c, d) -> IO SomeObject Source # |
FromPy
instances indicate that a type can be marshalled from Python to Haskell automatically
For example, FromPy Integer
indicates that we know how to take some Python object and convert
it into a Haskell Integer. If the Python object is int
, then we can cast properly. Failed casts throw a PyCastException
fromPy :: SomeObject -> IO a Source #
Takes some Python object, and converts it to the corresponding Haskell type by going over FFI. Might throw a PyCastException
Generally you'll only need to call fromPy
manually on some type when writing your own FromPy
instances for another type
Instances
data PyCastException Source #
An exception representing a failed cast from a Python object to Haskell value, usually because the expected type of the Python object was not correct.
Carries a String
which represents the name of the expected Haskell type which caused a failed cast. If using easyFromPy
, this String
is found with typeRep
Instances
Exception PyCastException Source # | |
Defined in CPython.Simple.Instances | |
Show PyCastException Source # | |
Defined in CPython.Simple.Instances showsPrec :: Int -> PyCastException -> ShowS # show :: PyCastException -> String # showList :: [PyCastException] -> ShowS # |
:: Object p | |
=> (h -> IO p) | python to- conversion, e.g. Py.toFloat |
-> h | haskell type being converted |
-> IO SomeObject | Python object |
Helper that lets you convert a Haskell value to a Python object by providing both a Python conversion function (from the Haskell type, over FFI, to some Python Object) as well as the Haskell value
Lets you define toPy
with just a Python conversion function
:: (Concrete p, Typeable h) | |
=> (p -> IO h) | python from- conversion, e.g. Py.fromFloat |
-> Proxy h | proxy for the type being converted to |
-> SomeObject | python object to cast from |
-> IO h | Haskell value |
Helper that takes a conversion function and a Python object, and casts the Python object into a Haskell value.
Lets you define fromPy
with just a Python conversion function
We use Proxy
to infer the type name for use in case of a failed cast. In the context of defining an instance, this type will be inferrable, so you can just provide a Proxy
value