souffle-haskell-0.2.2: Souffle Datalog bindings for Haskell
Safe HaskellNone
LanguageHaskell2010

Language.Souffle.Marshal

Description

This module exposes a uniform interface to marshal values to and from Souffle Datalog. This is done via the Marshal typeclass and MarshalM monad. Also, a mechanism is exposed for generically deriving marshalling and unmarshalling code for simple product types.

Synopsis

Documentation

class Marshal a where Source #

A typeclass for providing a uniform API to marshal/unmarshal values between Haskell and Souffle datalog.

The marshalling is done via a stack-based approach, where elements are pushed/popped one by one. You need to make sure that the marshalling of values happens in the correct order or unexpected things might happen (including crashes). Pushing and popping of fields should happen in the same order (from left to right, as defined in Datalog).

Generic implementations for push and pop that perform the previously described behavior are available. This makes it possible to write very succinct code:

data Edge = Edge String String deriving Generic

instance Marshal Edge

Minimal complete definition

Nothing

Methods

push :: a -> MarshalM PushF () Source #

Marshals a value to the datalog side.

default push :: (Generic a, SimpleProduct a (Rep a), GMarshal (Rep a)) => a -> MarshalM PushF () Source #

pop :: MarshalM PopF a Source #

Unmarshals a value from the datalog side.

default pop :: (Generic a, SimpleProduct a (Rep a), GMarshal (Rep a)) => MarshalM PopF a Source #

Instances

Instances details
Marshal Int32 Source # 
Instance details

Defined in Language.Souffle.Marshal

Marshal String Source # 
Instance details

Defined in Language.Souffle.Marshal

Marshal Text Source # 
Instance details

Defined in Language.Souffle.Marshal

Marshal Text Source # 
Instance details

Defined in Language.Souffle.Marshal

data PushF a Source #

A data type used for serializing a Marshal-able value from Haskell to Souffle, only used internally.

Constructors

PushInt Int32 a 
PushStr String a 

Instances

Instances details
Functor PushF Source # 
Instance details

Defined in Language.Souffle.Marshal

Methods

fmap :: (a -> b) -> PushF a -> PushF b #

(<$) :: a -> PushF b -> PushF a #

data PopF a Source #

A data type used for deserializing a Marshal-able value from Souffle to Haskell, only used internally.

Constructors

PopInt (Int32 -> a) 
PopStr (String -> a) 

Instances

Instances details
Functor PopF Source # 
Instance details

Defined in Language.Souffle.Marshal

Methods

fmap :: (a -> b) -> PopF a -> PopF b #

(<$) :: a -> PopF b -> PopF a #

data MarshalM f a Source #

The monad used for serializing and deserializing of values that implement the Marshal typeclass.

Instances

Instances details
Functor f => Monad (MarshalM f) Source # 
Instance details

Defined in Language.Souffle.Marshal

Methods

(>>=) :: MarshalM f a -> (a -> MarshalM f b) -> MarshalM f b #

(>>) :: MarshalM f a -> MarshalM f b -> MarshalM f b #

return :: a -> MarshalM f a #

Functor f => Functor (MarshalM f) Source # 
Instance details

Defined in Language.Souffle.Marshal

Methods

fmap :: (a -> b) -> MarshalM f a -> MarshalM f b #

(<$) :: a -> MarshalM f b -> MarshalM f a #

Functor f => Applicative (MarshalM f) Source # 
Instance details

Defined in Language.Souffle.Marshal

Methods

pure :: a -> MarshalM f a #

(<*>) :: MarshalM f (a -> b) -> MarshalM f a -> MarshalM f b #

liftA2 :: (a -> b -> c) -> MarshalM f a -> MarshalM f b -> MarshalM f c #

(*>) :: MarshalM f a -> MarshalM f b -> MarshalM f b #

(<*) :: MarshalM f a -> MarshalM f b -> MarshalM f a #

interpret :: Monad m => (forall x. f x -> m x) -> MarshalM f a -> m a Source #

Helper function for interpreting the actual (de-)serialization of values. This allows both the compiled and interpreted variant to handle (de-)serialization in their own way.