[Haskell-cafe] When the unknown is unknown

Alexander Solla ajs at 2piix.com
Thu Jun 24 15:11:32 EDT 2010


On Jun 24, 2010, at 11:14 AM, Martin Drautzburg wrote:

> Another question is: how much past and future knowledge do I need.  
> (I believe
> the fundamental property of music is that things are ordered).  In  
> order to
> compute Volumes from Moments I can get pretty much away without the  
> past, but
> computing Moments from Volumes definitely requires knowing "where I  
> am",
> because each new Moment has to be placed after a preceding Moment.


You can use pattern matching against lists.  For example:

process_rhythm_scheme :: RhythmScheme -> Rhythm
process_rhythm_scheme ( (Just foo,  Just bar )
		      : (Just foo', Just bar')
	              : (Just foo'', Just bar'')
		      : rest ) = undefined

will match a RhythmScheme where the first three entries are wholly  
defined, and will bind its values to foo, bar, foo', bar', rest, and  
so on.

I think "View Patterns" could help control the complexity of these  
patterns.  http://hackage.haskell.org/trac/ghc/wiki/ViewPatterns.   
That page has quite a few nice constructs that could apply to your  
problem.  ("Both patterns", "iterator style")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100624/efca3057/attachment.html


More information about the Haskell-Cafe mailing list