[Haskell-cafe] dynamic code compilation and loading

Evan Laforge qdunkan at gmail.com
Mon Jan 16 23:38:42 UTC 2017

I used to use hint for a somewhat similar situation (I wanted to give
a REPL to my program, which incidentally is also concerned with
interpreting music).  I found that hint didn't give enough control (it
wanted to reload everything on every expression, instead of only
reloading when I told it to) and it was too hard to dig through it's
ghc compatibility layers, so I directly used the GHC API and it was a
lot easier than expected.

However, that's for inserting code into a running program.  If you
want to just run a function to transform a Score, couldn't you just
load the support modules in ghci, and run the main function from
there?  Change the source, type :r, and type 'main' again.  You could
hook up your editor to that automatically on every save.

By the way, I'm also interested in expressive score realization, since
I'm doing something similar, though in my case I'm using a custom
score format rather than staff notation.  If you have anything to show
off I'd be interested to see.

On Sun, Jan 15, 2017 at 12:37 PM, Dennis Raddle <dennis.raddle at gmail.com> wrote:
> Hello,
> I wrote a Haskell program which reads a MusicXML score and plays it through
> real-time MIDI messages (using the portmidi module) via some algorithms that
> are customized depending on the MIDI synthesizer that is receiving the
> messages. The program also plays back the music with musically expressive
> nuances.
> In the next version of this program, I am going to add more complicated
> algorithms for the expressive nuances, and it would be helpful to configure
> them and express them in actual Haskell code. My workflow will look like
> this:
> A. write a score using the music typesetting program Sibelius
> B. write some Haskell code to provide expressive nuances
> C. play the music through a MIDI synthesizer and listen.
> D. based on what I hear and where I want to take the music, modify the score
> and the Haskell code
> E. loop back to C
> Therefore, if I don't want to recompile the program each time I do step D, I
> need to compile and load code dynamically.
> Let's say that a data structure which contains a MusicXML score and a
> nominal rendition into MIDI messages together with time tags is of type
> Score. Then I want to write, and dynamically compile/load, a function
> vary :: Score -> Score
> which varies the MIDI messages and time tags to add expressive nuances.
> Let's say 'vary' is contained in Vary.hs.
> I want to write 'vary' in terms of already-compiled functions that provide
> the basic music-processing operations. Let's say that these functions are in
> the module MusicBase. Then Vary.hs will look like
> import MusicBase
> vary = ... operations in MusicBase ...
> Can I get some basic idea of how to do this?
> 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