raw-feldspar-0.2.1: Resource-Aware Feldspar

Safe HaskellNone
LanguageHaskell2010

Feldspar.Run.Marshal

Synopsis

Documentation

newtype Parser a Source #

Constructors

Parser 

Fields

Instances

Monad Parser Source # 

Methods

(>>=) :: Parser a -> (a -> Parser b) -> Parser b #

(>>) :: Parser a -> Parser b -> Parser b #

return :: a -> Parser a #

fail :: String -> Parser a #

Functor Parser Source # 

Methods

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

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

Applicative Parser Source # 

Methods

pure :: a -> Parser a #

(<*>) :: Parser (a -> b) -> Parser a -> Parser b #

(*>) :: Parser a -> Parser b -> Parser b #

(<*) :: Parser a -> Parser b -> Parser a #

readParser :: forall a. (Read a, Typeable a) => Parser a Source #

parse :: Parser a -> String -> a Source #

class MarshalHaskell a where Source #

Serialization/deserialization of Haskell values

The following property must hold for all a:

a = parse toHaskell (fromHaskell a) Prelude.== a

Methods

fromHaskell :: a -> String Source #

Serialize a Haskell value

fromHaskell :: Show a => a -> String Source #

Serialize a Haskell value

toHaskell :: Parser a Source #

Deserialize a Haskell value

toHaskell :: (Read a, Typeable a) => Parser a Source #

Deserialize a Haskell value

Instances

MarshalHaskell Double Source # 
MarshalHaskell Float Source # 
MarshalHaskell Int Source # 
MarshalHaskell Int8 Source # 
MarshalHaskell Int16 Source # 
MarshalHaskell Int32 Source # 
MarshalHaskell Int64 Source # 
MarshalHaskell Word8 Source # 
MarshalHaskell Word16 Source # 
MarshalHaskell Word32 Source # 
MarshalHaskell Word64 Source # 
MarshalHaskell a => MarshalHaskell [a] Source # 
MarshalHaskell (Complex Double) Source # 
MarshalHaskell (Complex Float) Source # 
(MarshalHaskell a, MarshalHaskell b) => MarshalHaskell (a, b) Source # 

Methods

fromHaskell :: (a, b) -> String Source #

toHaskell :: Parser (a, b) Source #

(MarshalHaskell a, MarshalHaskell b, MarshalHaskell c) => MarshalHaskell (a, b, c) Source # 

Methods

fromHaskell :: (a, b, c) -> String Source #

toHaskell :: Parser (a, b, c) Source #

(MarshalHaskell a, MarshalHaskell b, MarshalHaskell c, MarshalHaskell d) => MarshalHaskell (a, b, c, d) Source # 

Methods

fromHaskell :: (a, b, c, d) -> String Source #

toHaskell :: Parser (a, b, c, d) Source #

class MarshalHaskell (HaskellRep a) => MarshalFeld a where Source #

Serialization/deserialization of Feldspar values

Associated Types

type HaskellRep a Source #

The Haskell representation of a Feldspar value

Methods

fwrite :: Handle -> a -> Run () Source #

Serialize a Feldspar value to a handle

fwrite :: (PrimType b, Formattable b, a ~ Data b) => Handle -> a -> Run () Source #

Serialize a Feldspar value to a handle

fread :: Handle -> Run a Source #

Deserialize a Feldspar value from a handle

fread :: (PrimType b, Formattable b, a ~ Data b) => Handle -> Run a Source #

Deserialize a Feldspar value from a handle

Instances

MarshalFeld (Data Double) Source # 

Associated Types

type HaskellRep (Data Double) :: * Source #

MarshalFeld (Data Float) Source # 

Associated Types

type HaskellRep (Data Float) :: * Source #

MarshalFeld (Data Int8) Source # 

Associated Types

type HaskellRep (Data Int8) :: * Source #

MarshalFeld (Data Int16) Source # 

Associated Types

type HaskellRep (Data Int16) :: * Source #

MarshalFeld (Data Int32) Source # 

Associated Types

type HaskellRep (Data Int32) :: * Source #

MarshalFeld (Data Int64) Source # 

Associated Types

type HaskellRep (Data Int64) :: * Source #

MarshalFeld (Data Word8) Source # 

Associated Types

type HaskellRep (Data Word8) :: * Source #

MarshalFeld (Data Word16) Source # 

Associated Types

type HaskellRep (Data Word16) :: * Source #

MarshalFeld (Data Word32) Source # 

Associated Types

type HaskellRep (Data Word32) :: * Source #

MarshalFeld (Data Word64) Source # 

Associated Types

type HaskellRep (Data Word64) :: * Source #

MarshalFeld (Data (Complex Double)) Source # 

Associated Types

type HaskellRep (Data (Complex Double)) :: * Source #

MarshalFeld (Data (Complex Float)) Source # 

Associated Types

type HaskellRep (Data (Complex Float)) :: * Source #

(MarshalHaskell (Internal a), MarshalFeld a, Syntax a) => MarshalFeld (IArr a) Source # 

Associated Types

type HaskellRep (IArr a) :: * Source #

Methods

fwrite :: Handle -> IArr a -> Run () Source #

fread :: Handle -> Run (IArr a) Source #

(MarshalHaskell (Internal a), MarshalFeld a, Syntax a) => MarshalFeld (Arr a) Source # 

Associated Types

type HaskellRep (Arr a) :: * Source #

Methods

fwrite :: Handle -> Arr a -> Run () Source #

fread :: Handle -> Run (Arr a) Source #

MarshalFeld a => MarshalFeld (Nest a) Source #

Note that HaskellRep (Nest a) = (Length, Length, HaskellRep a) rather than [HaskellRep a]. This means that e.g. Nest (Nest (Fin (IArr a))) is represented as (Length,Length,(Length,Length,(Length,[...]))) instead of the more convenient [[...]].

Associated Types

type HaskellRep (Nest a) :: * Source #

Methods

fwrite :: Handle -> Nest a -> Run () Source #

fread :: Handle -> Run (Nest a) Source #

(Syntax a, MarshalHaskell (Internal a), MarshalFeld a) => MarshalFeld (Pull2 a) Source # 

Associated Types

type HaskellRep (Pull2 a) :: * Source #

Methods

fwrite :: Handle -> Pull2 a -> Run () Source #

fread :: Handle -> Run (Pull2 a) Source #

(Syntax a, MarshalHaskell (Internal a), MarshalFeld a) => MarshalFeld (Pull a) Source # 

Associated Types

type HaskellRep (Pull a) :: * Source #

Methods

fwrite :: Handle -> Pull a -> Run () Source #

fread :: Handle -> Run (Pull a) Source #

(MarshalFeld a, MarshalFeld b) => MarshalFeld (a, b) Source # 

Associated Types

type HaskellRep (a, b) :: * Source #

Methods

fwrite :: Handle -> (a, b) -> Run () Source #

fread :: Handle -> Run (a, b) Source #

(Syntax a, MarshalHaskell (Internal a), MarshalFeld a, (~) (* -> *) m Run) => MarshalFeld (Seq m a) Source # 

Associated Types

type HaskellRep (Seq m a) :: * Source #

Methods

fwrite :: Handle -> Seq m a -> Run () Source #

fread :: Handle -> Run (Seq m a) Source #

(Syntax a, MarshalHaskell (Internal a), MarshalFeld a, (~) (* -> *) m Run) => MarshalFeld (Push2 m a) Source # 

Associated Types

type HaskellRep (Push2 m a) :: * Source #

Methods

fwrite :: Handle -> Push2 m a -> Run () Source #

fread :: Handle -> Run (Push2 m a) Source #

(Syntax a, MarshalHaskell (Internal a), MarshalFeld a, (~) (* -> *) m Run) => MarshalFeld (Push m a) Source # 

Associated Types

type HaskellRep (Push m a) :: * Source #

Methods

fwrite :: Handle -> Push m a -> Run () Source #

fread :: Handle -> Run (Push m a) Source #

(MarshalFeld a, MarshalFeld b, MarshalFeld c) => MarshalFeld (a, b, c) Source # 

Associated Types

type HaskellRep (a, b, c) :: * Source #

Methods

fwrite :: Handle -> (a, b, c) -> Run () Source #

fread :: Handle -> Run (a, b, c) Source #

(MarshalFeld a, MarshalFeld b, MarshalFeld c, MarshalFeld d) => MarshalFeld (a, b, c, d) Source # 

Associated Types

type HaskellRep (a, b, c, d) :: * Source #

Methods

fwrite :: Handle -> (a, b, c, d) -> Run () Source #

fread :: Handle -> Run (a, b, c, d) Source #

writeStd :: MarshalFeld a => a -> Run () Source #

Write a value to stdout

readStd :: MarshalFeld a => Run a Source #

Read a value from stdin

connectStdIO :: (MarshalFeld a, MarshalFeld b) => (a -> Run b) -> Run () Source #

Connect a Feldspar function between serializable types to stdin/stdout

streamStdIO :: (MarshalFeld a, MarshalFeld b) => (a -> Run b) -> Run () Source #

Connect a Feldspar function between serializable types to stdin/stdout. The inputoutput will be in the form of a list as recognized by toHaskell fromHaskell (i.e. the length followed by the elements in sequence).

The function will be mapped over the input list in a lazy manner.

marshalled' Source #

Arguments

:: (MarshalFeld a, MarshalFeld b) 
=> CompilerOpts 
-> ExternalCompilerOpts 
-> (a -> Run b)

Function to compile

-> ((HaskellRep a -> IO (HaskellRep b)) -> IO c)

Function that has access to the compiled executable as a function

-> IO c 

A version of marshalled that takes ExternalCompilerOpts as additional argument

marshalled Source #

Arguments

:: (MarshalFeld a, MarshalFeld b) 
=> (a -> Run b)

Function to compile

-> ((HaskellRep a -> IO (HaskellRep b)) -> IO c)

Function that has access to the compiled executable as a function

-> IO c 

Compile a function and make it available as an IO function. Note that compilation only happens once, even if the function is used many times in the body.

For example, given the following Feldspar function:

sumArr :: DIArr Int32 -> Run (Data Int32)
sumArr arr = do
    r <- initRef 0
    for (0,1,Excl $ length arr) $ \i -> modifyRef r (+ arrIx arr i)
    unsafeFreezeRef r

marshalled can be used as follows:

*Main> marshalled sumArr $ \f -> (f [3,4,5] >>= print) >> (f [6,7,8,9] >>= print)

marshalledStream' Source #

Arguments

:: (MarshalFeld a, MarshalFeld b) 
=> CompilerOpts 
-> ExternalCompilerOpts 
-> (a -> Run b)

Function to compile

-> (([HaskellRep a] -> IO [HaskellRep b]) -> IO c)

Function that has access to the compiled executable as a function

-> IO c 

A version of marshalledStream that takes ExternalCompilerOpts as additional argument

marshalledStream Source #

Arguments

:: (MarshalFeld a, MarshalFeld b) 
=> (a -> Run b)

Function to compile

-> (([HaskellRep a] -> IO [HaskellRep b]) -> IO c)

Function that has access to the compiled executable as a function

-> IO c 

Compile a function and make it available as an IO function. The compiled function will be applied repeatedly over the list of inputs producing a list of outputs. Note that compilation only happens once, even if the function is used many times in the body.