[Haskell-cafe] evaluate arbitrary code + mutable variables

Jeffrey Brown jeffbrown.the at gmail.com
Wed May 13 00:02:35 UTC 2015


Half solved!

David Gladstein pointed out that GHCI's "it" variable can at least
sometimes solve the problem:

  Prelude System.IO> let x = 3
  Prelude System.IO> x
  3
  Prelude System.IO> let x = it + 1
  Prelude System.IO> x
  4

Then I discovered that in GHCI one can bind monadically:

  Prelude> x <- return 3
  Prelude> x <- return $ x + 1
  Prelude> x
  4

  Prelude> x <- getLine
  This line was user input, not computer output.
  Prelude> x
  "This line was user input, not computer output."
  Prelude>

I don't remember seeing anyone demonstrate it; perhaps it is deprecated.

I would still very much like to know whether and if so how it is possible
to let the user evaluate arbitrary haskell when running compiled code.

On Tue, May 12, 2015 at 1:19 PM, Jeffrey Brown <jeffbrown.the at gmail.com>
wrote:

> I wrote a graph-like data type, with some functions for adding statements
> and relationships between statements. (It's different from a graph in that
> there's no edge/vertex distinction; there are only statements, but a
> statement might refer to other statements.)
>
> Currently I'm using them in GHCI. Because it does not allow one to change
> a variable, I keep having to do things like this:
>   let g0 = emptyDocument
>   let s1 = newStatement ...
>   let g1 = addStatement s1 g0
>   let s2 = newStatement ...
>   let g2 = addStatement s2 g1
>   ...
> If I wrote a standalone application, I could use mutable variables, so I
> would not have to define a new object every time I want to modify an
> existing one. However I like being able to type in arbitrary code into GHCI.
>
> Can one have both of those at once? That is, could I either (1) use MVars
> from within GHCI, or (2) write a standalone app that lets the user evaluate
> arbitrary Haskell?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150512/33891214/attachment.html>


More information about the Haskell-Cafe mailing list