erlang-0.2: 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

Low-level communication with the Erlang Port-Mapper Daemon

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)

Representation of Erlang nodes

type Name = String Source

Name of an Erlang node.

type Ip = String Source

Ip address of a remote Erlang node.

data Node Source

Representation of an Erlang node on the network.

Constructors

Short Name

Local Erlang node.

Long Name Ip

Remote Erlang node.

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.

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. In Erlang equivalent to

{Node, Pid} ! Msg.

Native Erlang data types

Conversion between native Haskell types and ErlType

class Erlang a where Source

Instances

Easy type-safe access to tuple members

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

Internal packing functions

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.