<div dir="ltr"><font face="monospace, monospace">In my music translation program, I have a ton of data and configuration that goes into every note computation, so I've decided to use the State monad to pass it around. Also, the generated output is just a list of MIDI events, so I think I'll use Writer to gather the output. </font><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">I will be dealing with several different MIDI synthesizers, which have different specifications and manner of control. But there is enough in common that I can write a single function to do the translation, provided that I provide that function with some data that is specific to the synth, and also I need to configure it with some functions specific to the synth. </font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">Let's say my State/Writer type is called Tr.</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">type Tr a = StateT Configuration (Writer [MidiEvent]) a</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">This is the data I provide to StateT:</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">data Configuration = Configuration</font></div><div><font face="monospace, monospace">  { t1 :: SynthSpecificData</font></div><div><font face="monospace, monospace">  , f1 :: Tr SynthSpecificComputationResult</font></div><div><font face="monospace, monospace">  , score :: WholeMusicalScore</font></div><div><font face="monospace, monospace">  }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">So I need to write </font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">translate :: Tr ()</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">computeMidiEvents = runWriter (runStateT translate theConfig)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">So inside 'translate' I want to call 'f1' among many other things. Let's just consider the f1 call first. I wrote this first:</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">translate = do</font></div><div><font face="monospace, monospace">  f <- gets f1</font></div><div><font face="monospace, monospace">  f</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">That works but looks a little weird. I think this works also:</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">translate = join (gets f1)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">Is that better?</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">D</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><br></font></div></div>