Réf. : Re: [Haskell-cafe] GHCi and State

corentin.dupont at ext.mpsa.com corentin.dupont at ext.mpsa.com
Fri Jun 25 08:54:14 EDT 2010


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                                                 
             <allbery at ece.cmu                                         Pour 
             .edu>                     haskell-cafe at haskell.org            
             Envoyé par :                                               cc 
             haskell-cafe-bou                                              
             nces at haskell.org                                        Objet 
                                       Re: [Haskell-cafe] GHCi and State   
                                                                           
             25/06/2010 11:30                                              
                                                                           
                                                                           
                                                                           
                                                                           




-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 6/25/10 05:07 , corentin.dupont at ext.mpsa.com wrote:
> 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?

GHC API.  This is likely biting off more than you want to chew, though;
it'll probably be easier to write your own interpreter,

> 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
this
> monad?

  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 ...

> 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
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 at kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allbery at 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 at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe




More information about the Haskell-Cafe mailing list