I have two, related questions about RPC call to Yesod/Snap/Servant
:
Say I have a function on the server, written in Haskell, compiled by GHC:
add x y = x+y+42
How can:
- I call this function from the client (the client is also written in Haskell, compiled with
GHCJS
), - execute the function on the server,
- return the result to the client?
Do all this in a type-safe way?
So for example, I would like to write something like this on the client:
main= putStrLn $ show $ add 2 3
Such that the add function gets executed on the server.
What is the simplest way of doing this using Yesod/Snap/Servant
on the server and GHCJS on the client?
2) Similarly, I would like to write a "function" :
getPhaseOfMoon :: IO Phase
which runs on the server and I would like to call getPhaseOfMoon
from the client in a type-safe way.
So that I can write this on the client:
main= do
p<-getPhaseOfMoon
putStrLn $ show p
return ()
Which
- goes to the server
- the server consults the phase of the moon
- the server returns
Phase
to the client - the client displays the phase of the moon in the JavaScript Console.
Question
How can I do this with Yesod/Snap/Servant
(server) + GHCJS (client)?