erlang-0.2.3: FFI interface to Erlang.

Copyright(c) Eric Sessoms 2008
(c) Artúr Poór 2015
LicenseGPL3
Maintainergombocarti@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell98

Foreign.Erlang

Contents

Description

Speaks the Erlang network protocol and impersonates an Erlang node on the network. Fully capable of bi-directional communication with Erlang. Erlang types are, as far as reasonable, mapped to Haskell types. Messages to Erlang are just function calls in Haskell, and messages from Erlang are delivered to MVars.

Synopsis

Documentation

type HostName = String #

Either a host name e.g., "haskell.org" or a numeric host address string consisting of a dotted decimal IPv4 address or an IPv6 address e.g., "192.168.0.1".

data Node Source #

Representation of an Erlang node on the network.

Constructors

Short Name

Local Erlang node.

Long Name HostName

Remote Erlang node.

Instances
Eq Node Source # 
Instance details

Defined in Foreign.Erlang.Network

Methods

(==) :: Node -> Node -> Bool #

(/=) :: Node -> Node -> Bool #

Show Node Source # 
Instance details

Defined in Foreign.Erlang.Network

Methods

showsPrec :: Int -> Node -> ShowS #

show :: Node -> String #

showList :: [Node] -> ShowS #

Erlang Node Source # 
Instance details

Defined in Foreign.Erlang.Network

type Name = String Source #

Name of an Erlang node.

epmdGetNames :: IO [String] Source #

Return the names and addresses of registered local Erlang nodes.

epmdGetPort :: Node -> IO Int Source #

Return the port address of a named Erlang node.

epmdGetPortR4 :: String -> String -> IO (Int, Int, Int, Int, Int, String, String) Source #

Returns (port, nodeType, protocol, vsnMax, vsnMin, name, extra)

High-level communication

genCall :: Erlang a => MBox -> Node -> Pid -> a -> IO ErlType Source #

gen_server:call(Pid, Msg)

genCast :: Erlang a => MBox -> Node -> Pid -> a -> IO () Source #

gen_server:cast(Pid, Msg)

rpcCall :: MBox -> Node -> String -> String -> [ErlType] -> IO ErlType Source #

rpc:call(Node, Module, Function, Arguments)

rpcCast :: MBox -> Node -> String -> String -> [ErlType] -> IO () Source #

rpc:cast(Node, Module, Function, Arguments)

Mnesia database methods

Low-level communication

Representation of a Haskell node (program)

data Self Source #

Represents a Haskell node. There should be one of these per process.

createSelf :: String -> IO Self Source #

Instantiate a Haskell node. This initializes the FFI. Node name should be a 'long name' e.g. "haskell@localhost".

Representation of a Haskell process (thread)

data MBox Source #

Haskell threads don't natively have Erlang process IDs. Instead, we use a mailbox abstraction that we can assign PIDs to for communication with Erlang.

createMBox :: Self -> IO MBox Source #

Create a new process on the Haskell side. Usually corresponds to a thread but doesn't need to.

mboxRef :: MBox -> IO ErlType Source #

Return a new unique object reference.

mboxSelf :: MBox -> ErlType Source #

Return the PID of the given mailbox.

Representation of Erlang nodes and processes

type Pid = Either ErlType String Source #

Represents a foreign (Erlang) process. A process can be identified either by its low-level ID (Left pid) or by its registered name (Right name).

Communication to and from Erlang

mboxRecv :: MBox -> IO ErlType Source #

Receive the next message addressed to this mailbox.

mboxRecv' :: MBox -> ErlType -> IO ErlType Source #

Receive a reply message. That is, looks for the next message identified by the given reference.

mboxSend :: Erlang a => MBox -> Node -> Pid -> a -> IO () Source #

Send an arbitrary message to the specified node and process. It is equivalent in Erlang to

{Node, Pid} ! Msg.

class Erlang a where Source #

Minimal complete definition

toErlang, fromErlang

Instances
Erlang Bool Source # 
Instance details

Defined in Foreign.Erlang.Types

Erlang Double Source # 
Instance details

Defined in Foreign.Erlang.Types

Erlang Float Source # 
Instance details

Defined in Foreign.Erlang.Types

Erlang Int Source # 
Instance details

Defined in Foreign.Erlang.Types

Erlang Integer Source # 
Instance details

Defined in Foreign.Erlang.Types

Erlang String Source # 
Instance details

Defined in Foreign.Erlang.Types

Erlang ErlType Source # 
Instance details

Defined in Foreign.Erlang.Types

Erlang Node Source # 
Instance details

Defined in Foreign.Erlang.Network

Erlang a => Erlang [a] Source # 
Instance details

Defined in Foreign.Erlang.Types

Methods

toErlang :: [a] -> ErlType Source #

fromErlang :: ErlType -> [a] Source #

Erlang [ErlType] Source # 
Instance details

Defined in Foreign.Erlang.Types

(Erlang a, Erlang b) => Erlang (a, b) Source # 
Instance details

Defined in Foreign.Erlang.Types

Methods

toErlang :: (a, b) -> ErlType Source #

fromErlang :: ErlType -> (a, b) Source #

(Erlang a, Erlang b, Erlang c) => Erlang (a, b, c) Source # 
Instance details

Defined in Foreign.Erlang.Types

Methods

toErlang :: (a, b, c) -> ErlType Source #

fromErlang :: ErlType -> (a, b, c) Source #

(Erlang a, Erlang b, Erlang c, Erlang d) => Erlang (a, b, c, d) Source # 
Instance details

Defined in Foreign.Erlang.Types

Methods

toErlang :: (a, b, c, d) -> ErlType Source #

fromErlang :: ErlType -> (a, b, c, d) Source #

(Erlang a, Erlang b, Erlang c, Erlang d, Erlang e) => Erlang (a, b, c, d, e) Source # 
Instance details

Defined in Foreign.Erlang.Types

Methods

toErlang :: (a, b, c, d, e) -> ErlType Source #

fromErlang :: ErlType -> (a, b, c, d, e) Source #

nth :: Erlang a => Int -> ErlType -> a Source #

Miscellaneous utilities

erlangTimeToSeconds :: Integral a => ErlType -> a Source #

Convert a tuple (from erlang:now()) to seconds from Jan 1, 1970.

secondsToErlangTime :: Integral a => a -> ErlType Source #

Convert seconds to an Erlang tuple representing time.