[Haskell-beginners] learning to use Haskell types

Michael Mossey mpm at alumni.caltech.edu
Sat Aug 15 10:36:46 EDT 2009


This is really a general question, but any advice is welcome.

I'm currently working through Typeclassopedia and all the tutorials it 
links to. I'm really enjoying it, but a kind of scary question is: when I 
begin to write "real" software in Haskell, how will I find natural places 
to use the types and how will I make the transition to idiomatic Haskell?

[Note: the main application I have for Haskell is my music composition 
hobby. I plan to use Haskell to write software for editing music and for 
computer-assisted composition (CAC). CAC means the computer does some of 
the tedious work involved in searching for, and evaluation of, combinations 
of musical themes. All my algorithms are personal to my own process. There 
is no off-the-shelf software that can help me. That's why it's fortunate 
I'm a programmer. The CAC features need to be tightly integrated into a 
musical score editor, hence I have to write that too. Really quite a fun 
project, and even if it takes two years, I will get years and years of 
enjoyment from it!]

Then it occurred to me that a common theme in Haskell is to provide a way 
to express a solution to a problem in an expressive form that is natural to 
that problem. So maybe what I need to do is stop thinking, "Where can I use 
this type," and instead dream up ways to express ideas in a simple and 
natural form, then make use of Haskell types and type classes to make that 
expressive form a reality.

For example, in a music editor, there are many actions that create new 
notes. A note needs many pieces of information to describe it: the note's 
place in time, its duration, dynamics, whether tied to successive notes, 
type of flag or beam... Much of this information can be inferred from the 
context in which the note is created, and so a natural expressive language 
would bring a new note into existence with a minimal need for providing 
details. Those details would be inferred from the context. So that's a 
Reader monad right there.

Thanks,
Mike





More information about the Beginners mailing list