Skip to content

Commit

Permalink
Slight simplification in server.lhs
Browse files Browse the repository at this point in the history
We can find the connection in the client tuple, so it's one less argument to pass to the `talk`function.
  • Loading branch information
OlivierSohn authored and jaspervdj committed May 11, 2018
1 parent 8625ff1 commit d67dff1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions example/server.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ the list and broadcast the fact that he has joined. Then, we give control to the
> T.intercalate ", " (map fst s)
> broadcast (fst client `mappend` " joined") s'
> return s'
> talk conn state client
> talk client state
> where
> prefix = "Hi! I am "
> client = (T.drop (T.length prefix) msg, conn)
Expand All @@ -144,8 +144,8 @@ the list and broadcast the fact that he has joined. Then, we give control to the
The talk function continues to read messages from a single client until he
disconnects. All messages are broadcasted to the other clients.

> talk :: WS.Connection -> MVar ServerState -> Client -> IO ()
> talk conn state (user, _) = forever $ do
> talk :: Client -> MVar ServerState -> IO ()
> talk (user, conn) state = forever $ do
> msg <- WS.receiveData conn
> readMVar state >>= broadcast
> (user `mappend` ": " `mappend` msg)

0 comments on commit d67dff1

Please sign in to comment.