[Haskell-cafe] here's my solution for scripting/interpreter approach

amindfv at gmail.com amindfv at gmail.com
Sun Feb 12 22:11:39 UTC 2017


Hi Dennis -- responses inline:

> El 11 feb 2017, a las 23:06, Dennis Raddle <dennis.raddle at gmail.com> escribió:
> 
> My application needed the flexibility of writing test code and running it, or configuring its job (playback of music) through Haskell code and immediately testing the result (i.e. making sound and listening). I thought I would use GHCI, but I ran into some trouble. For one thing, my program forks a thread to do the timed control of the music, while the main thread implements a REPL-like "control loop" -- i.e. let me enter commands to influence the playback or halt it. I think this was crashing GHCI, perhaps when an interpreted script forks a thread which is still alive when control returns to the GHCI prompt. Not sure.
> 

Would you mind sharing your code? GHCi should certainly not be crashing just because there was a forked background thread. I have done lots of the interaction you're describing (for music, also) and never had a problem like that.


> Anyway here's what I did. Now the process that does real-time control of the playback is an entirely separate process. The control loop is started by me first, and depending on the command I enter, it builds the playback program with "ghc --make" and then spawns it. I send it signals from the control loop.
> 
> This turns out to be great. I can make changes anywhere in my playback application, from the deepest utility library to the top-level configuration script, and it builds as needed before running. 
> 
> And, in the case it doesn't need to build anything, "ghc --make" finishes quickly so it doesn't feel inefficient to invoke it after every command I enter in the control loop.
> 

This seems like a great solution, the only downside being that you can't directly share memory between the processes. If you'd like to do that, I recommend (careful use of!) the "foreign-store" library, which allows you to regain references you stored before a ":r" in ghci.

Tom


> D
> 
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.


More information about the Haskell-Cafe mailing list