[Haskell-cafe] evaluate arbitrary code + mutable variables

amindfv at gmail.com amindfv at gmail.com
Thu May 14 12:40:29 UTC 2015


Using monadic bind in ghci is not at all deprecated -- it's one of the main ways people interact with ghci. MVar, iorefs, etc also work within ghci. Almost anything you can do in haskell you can do in ghci.

Tom


El May 12, 2015, a las 20:02, Jeffrey Brown <jeffbrown.the at gmail.com> escribió:

> 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?
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150514/a87e36e9/attachment.html>


More information about the Haskell-Cafe mailing list