
Hello, thank you for your answer. Brandon, Indeed I think that i should write my own interpreter for a first version of the game. I would be very instructive. But then, i'd like that the player could use the full power of Haskell to write their own rules during game play. Neat functions like map, filter etc. could be used by the player to write rules. Perhaps Hint is good for me.
take a look at the lambdabot source for the pitfalls of passing arbitrary user-provided code to GHCi (or GHC API), and how to avoid them. (In particular, if you're using GHC to parse your rules, what stops the user code from mangling the GameState on you?)
The code passed is not that arbitrary, it must have type "Rule".
This type would enforce certain constructions, and actions...
Roman,
for GHCi, i will try an IORef. Too bad i allready coded it using "StateT
GameState IO ()" extensively through the code ;)
Corentin
Brandon S
Allbery KF8NH
Instead of writing my own reader/interpreter, i'd like to use GHC to compil them on the fly, and then add them to the current "legislation". What would you suggest me to do that? Any pointers?
2. For now, the game is more or less playable in GHCi. But my concern is: When you use GHCi, you are in the IO monad, right? How to had state to
GHC API. This is likely biting off more than you want to chew, though; it'll probably be easier to write your own interpreter, this
monad?
I would like that the player can compose his rule in GHCi, and when he is done, he can submit it in GHCi with something like:
*Nomic> submitRule <myrule>
And then the game takes the rule, possibly modify the current legislation, and give the hand back to GHCi. So the "current legislation" has to be a state of the GHCi's loop. Is
runStateT nomicGame initialState :: IO (a,GameState) -- nomicGame :: StateT GameState IO a -- initialState :: GameState -- use evalStateT instead of runStateT if all you want is the result, -- or execStateT if all you want is the final state. -- if you want neither: -- _ <- runStateT ... this
possible at all?
Use an IORef to contain the state, if you really want to go this way. I wouldn't; take a look at the lambdabot source for the pitfalls of passing arbitrary user-provided code to GHCi (or GHC API), and how to avoid them. (In particular, if you're using GHC to parse your rules, what stops the user code from mangling the GameState on you?) - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkwkdygACgkQIn7hlCsL25WfhgCgo2qfkoA0yBaXsrjQNT+xePSb vJMAnjLQnOtaByKXSsFvLuclcFt7vhEg =jnru -----END PGP SIGNATURE----- _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe