On Mon, 21 Mar 2016, amin...@gmail.com wrote: > Resurrecting a pretty old thread here, but I think I've found a nice way > to crack this problem, which I use in Vivid 0.2 -- thought I'd give a > run-down: > > If you'll recall, when we last saw our heros they were struggling with > the inability to have 3 things in our UGens simultaneously: > > - Default argument values: if we don't use records we need to require all > arguments, and so we'd need to e.g. provide a "phase" to every SinOsc > - Type-checked arguments: if we use records to represent our values, we > can't use "freq" only on the ugens it makes sense on: someone could > accidentally give WhiteNoise a freq. We could make them unambiguous, but we > also want... > - Short argument names: nobody wants to write "sinOscFreq" - they want to > write "freq"!
I just watched the interface of vivid and wondered about the scary types. I think it would be possible even in Haskell 98 to have something like this: sinOsc :: UGen SinOsc freq :: (Freq typ) => Float -> UGen typ -> UGen typ phase :: (Phase typ) => Float -> UGen typ -> UGen typ class Freq typ where setFreq :: typ -> typ instance Freq SinOsc where setFreq f args = args {sinOscFreq = f} instance Phase SinOsc where ... SinOsc is the record holding the arguments for a sine oscillator. Then you could write: phase (pi/2) $ freq 800 sinOsc -- Read the whole topic here: Haskell Art: http://lurk.org/r/topic/I5rZKvj6KuAhGvpTSWQV7 To leave Haskell Art, email haskell-...@group.lurk.org with the following email subject: unsubscribe