[plt-scheme] code organization question
karczma at info.unicaen.fr wrote:
> Stephen Tetley writes:
>
>> but using proper constructors makes note descriptions very long even
>> with defaults.
>
>
karczma at info.unicaen.fr wrote:
> Please, check Haskore, and other work of Paul Hudak!
>
> http://haskell.org/haskore/
> http://cs-www.cs.yale.edu/homes/hudak.html
>
>
Yes, Paul Hudak's Haskore does make very elegant use of (short)
constructors for pitches and similarly named functions that work like
constructors for notes which have pitch, octave and duration.
For people without The Haskell School of Expression handy...
Pitch Class is an algebraic type with constructors for each pitch class
value:
data PitchClass = Cf | C | Cs | Df | D | Ds etc...
Then there similarly named functions to create notes: a pair of (pitch
class & octave) together with a duration:
cf o = Note (Cf, o) -- actually a curried function which then takes a
duration.
Middle C for a duration of 1 becomes: c 4 1
Thus, you can describe a scale as [c 4 1, d 4 1, e 4 1, f 4 1, g 4 1, a
4 1, b 4 1, c 5 1] with the potential to factor out the octaves and
durations through list comprehensions, e.g. :
[n 1 | n <- c 4, d 4, e 4, f 4, g 4, a 4, b 4, c 5] ] -- for this
example, octave has to remain to account for the last note being one
octave higher
Maybe there is a design alternative Yoav could try in MzScheme following
the idea of 'psuedo' contructors as the user level interface to the
sound type rather than proper constructors. Library implementers would
then provide an implementation of the pseudo constructors for their
particular sound type.
Stephen