[plt-scheme] code organization question

From: Stephen Tetley (rt014i7347 at blueyonder.co.uk)
Date: Mon Oct 17 18:33:26 EDT 2005

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 

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 

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.


Posted on the users mailing list.