You need to install stack
first.
Simply run ./start.sh
. This command will compile and start your project.
There is no client 😛. But we have telnet:
franco@xinaiu:~/tmp/ping-pong-hs$ telnet localhost 3500
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
read
set:hello
hello
read
hello
set:world
world
read
world
clear
read
set:persistent
persistent
quit
Connection closed by foreign host.
franco@xinaiu:~/tmp/ping-pong-hs$ telnet localhost 3500
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
read
persistent
As you can see, data is persistent thanks to STM
and IO
Our server is quite limited, it is a table of just one unnamed slot. We want to extend it so that it works with multiple slots and has richer operations:
franco@xinaiu:~/tmp/ping-pong-hs$ telnet localhost 3500
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
schema:name:surname:house
<OK>
read:name
set:name:jon
jon
set:lastname:snow
snow
set:house:stark
stark
clear:lastname
set:lastname:spoiler
spoiler
clear_all
read:lastname
read:name
read:house
set:name:arya
arya
reverse:name
ayra
upcase:name
AYRA
The goal of this project is to extend this code so that the previous commands work.
- Read this: https://www.reddit.com/r/haskell/comments/25xyts/how_about_an_stm_hash_table_implementation/.
- You can implement the table as an inmutable list of string keys and (mutable)
TVar
values. - The
schema
operation may destroy all data. - don't try to change
Main
andServer
alot. Intead, focus on theRehs
module, which declares its transactional primitive functions, andCommands
module, which parses strings into transactions. - notice that
Rehs.Server
andRehs.IO
actually deal withIO
, but other modules just work withSTM
and pure functions. If you start to write manyIO
functions, you are probably doing it wrong.
Make the table schema-less. You can use use TArray
's if you want.