@@ -33,13 +33,21 @@ from other nodes. We'll look at inter-node communication later, so for now
33
33
it will suffice to pass the default remote table, which defines the built-in
34
34
stuff Cloud Haskell needs at a minimum.
35
35
36
+ Let's start with imports first:
37
+
38
+ {% highlight haskell %}
39
+ import Network.Transport.TCP (createTransport, defaultTCPParameters)
40
+ import Control.Distributed.Process
41
+ import Control.Distributed.Process.Node
42
+ {% endhighlight %}
43
+
36
44
Our TCP network transport backend needs an IP address and port to get started
37
45
with, and we're good to go...
38
46
39
47
{% highlight haskell %}
40
48
main :: IO ()
41
49
main = do
42
- Right (t, _ ) <- createTransport "127.0.0.1" "10501" defaultTCPParameters
50
+ Right t <- createTransport "127.0.0.1" "10501" defaultTCPParameters
43
51
node <- newLocalNode t initRemoteTable
44
52
....
45
53
{% endhighlight %}
@@ -57,12 +65,12 @@ will send one to ourselves!
57
65
{% highlight haskell %}
58
66
-- in main
59
67
_ <- forkProcess node $ do
60
- -- get our own process id
61
- self <- getSelfPid
62
- send self "hello"
63
- hello <- expect :: Process String
64
- liftIO $ putStrLn hello
65
- return ()
68
+ -- get our own process id
69
+ self <- getSelfPid
70
+ send self "hello"
71
+ hello <- expect :: Process String
72
+ liftIO $ putStrLn hello
73
+ return ()
66
74
{% endhighlight %}
67
75
68
76
Lightweight processes are implemented as ` forkIO ` threads. In general we will
@@ -83,7 +91,7 @@ Let's spawn another process on the same node and make the two talk to each other
83
91
{% highlight haskell %}
84
92
main :: IO ()
85
93
main = do
86
- Right (t, _ ) <- createTransport "127.0.0.1" "10501" defaultTCPParameters
94
+ Right t <- createTransport "127.0.0.1" "10501" defaultTCPParameters
87
95
node <- newLocalNode t initRemoteTable
88
96
_ <- forkProcess node $ do
89
97
echoPid <- spawnLocal $ forever $ do
0 commit comments