Toy application advice wanted

Hi folks, I've got an interesting task this week for my job. (Note that this will undoubtably last for longer than a week). I'm evaluating several high-level languages as development vehicles for our next suite of applications. The languages I'm currently considering are Scheme, Erlang, and Haskell. Scheme and Haskell have fairly wide acceptance in their particular roles (Scheme as the "pretty" lisp, supporting higher-order functions and mostly strict [until you roll your own laziness with macros], and Haskell the absolute purest language with no side effects and fully lazy evaluation). Erlang has a really nice distributed computing model, and has a nice union of non- and side-effect qualities (although it's completely strict). The toy application I've "designed" for myself is a simple GUI-based app that can load a Sun .au format sound file, display its waveform in a window, perform some simple filtering, play the sound for the user, and then save the changed sound file back out to disk. If I get familiar enough with the respective environments I'd like to add zooming in/out and scrolling to the waveform display. This application should allow me to see all kinds of different characteristics of the language/implementation, such as performance (how fast can the filter run), I/O (how fast can I load/save data to disk), OS interaction (how easy can I "play" the audio), user acceptance (how easy is it to do GUI programming) and of course the software engineering goals of modularity, correctness, and simplicity. The end goal is for me to have three working programs, in three different languages, so that I can present to my boss the performance/software engineering characteristics of each system to choose our next development language. So I'm writing you to solicit help. I have an amortized four days (32 hours!!!) to implement this simple application in Haskell. Can anyone point me to example code, supporting libraries, tutorials, etc. that are in this area of development? If I have to dumb down some of my application in order to make a great discovery about a language, that's fine. I'm expecting some great differences between these three programs. Any advice/pointers/flames welcome. Thanks in advance. Mike -- Mike J. Bell This is all just my opinion. "Outside of a dog, a book is man's best friend. Inside it's too dark to read." mikeb@manor.org

On Mon, 2004-05-03 at 16:52, mikeb@manor.org wrote:
The toy application I've "designed" for myself is a simple GUI-based app that can load a Sun .au format sound file, display its waveform in a window, perform some simple filtering, play the sound for the user, and then save the changed sound file back out to disk. If I get familiar enough with the respective environments I'd like to add zooming in/out and scrolling to the waveform display.
Here's my positive experience with GUI programming in Haskell; I've been hacking on gtk2hs recently - the Haskell bindings for Gtk+ 2.x. Yesterday I wrote toy program as a demo. It's a viewer for GHC's timing profile log files. It parses a log file, populates a tree view with the data and allows you to vary a cut-off threshold on the data. It took about 4hrs to write and comes to less than 250 lines of code in two modules. The parsing is a bit slow (15sec to parse >850k log) because I used my patented zero-optimisation(tm) technique. :-) There are plenty of not-too difficult techniques for making the parsing go faster if you care about performance. (eg use a lexer and parsec or happy) If I were going to try and do your toy app I'd consider these things: Haskell's standard IO facilities are primarily text-oriented and designed for convenience rather than performance. If performance is important I'd look at some of GHC's low-level IO facilities: http://www.haskell.org/ghc/docs/latest/html/libraries/base/GHC.IO.html#v%3As... Eg load the whole file into memory and then use the marshaling facilities of Haskell's FFI to read the records out of your file. (I'm guessing here that .au files are basically a binary file with a header followed by an array of records) For playing a sound file either pipe it to an external command line player utility - see POpen for this, or you'll have to bind to some existing C library that plays .au files. This would be harder (ie take longer) but doable, see hsc2hs or c2hs for preprocessors that help with creating bindings for C libraries. For the GUI I'd obviously recommend Gtk+ and gtk2hs. If you need a cross-patform GUI, there's wxHaskell - which also has a nicer mid-level wrapper library at the moment. gtk2hs will allow you to use Glade which makes designing the GUI much easier and quicker. For the waveform display you can either draw directly into a DrawWindow or draw into a Pixmap (an off-screen buffer) and then display the pixmap in a DrawWindow or GtkImage widget.
This application should allow me to see all kinds of different characteristics of the language/implementation, such as performance (how fast can the filter run), I/O (how fast can I load/save data to disk), OS interaction (how easy can I "play" the audio), user acceptance (how easy is it to do GUI programming) and of course the software engineering goals of modularity, correctness, and simplicity.
I'd say that modularity, correctness, and simplicity are Haskell's strengths while low-level high performance bit shifting is not. No doubt, Haskell would allow you to build elegant type-safe abstractions for dealing with large binary files, but that's an investment that's hard to justify for a prototype and getting good performance would require careful thought. Duncan

On May 3, 2004, at 5:52 PM, mikeb@manor.org wrote:
I've got an interesting task this week for my job. (Note that this will undoubtably last for longer than a week). I'm evaluating several high-level languages as development vehicles for our next suite of applications. The languages I'm currently considering are Scheme, Erlang, and Haskell...
The toy application I've "designed" for myself is a simple GUI-based app that can load a Sun .au format sound file, display its waveform in a window, perform some simple filtering, play the sound for the user, and then save the changed sound file back out to disk. If I get familiar enough with the respective environments I'd like to add zooming in/out and scrolling to the waveform display...
I have an amortized four days (32 hours!!!) to implement this simple application in Haskell...
Any advice/pointers/flames welcome. Thanks in advance.
Frankly, I think it's completely unrealistic to expect to be able to fairly evaluate Haskell in 32 hours. As you noted yourself, Scheme and Erlang, being strict, are much closer to conventional programming languages than Haskell is, so it's easier to transfer skills to them. Furthermore, they're untyped, and learning how to exploit Haskell's static typing is one of the bigger hurdles to learning how to exploit Haskell. Even if, as you wrote in a later post, you lower your sights to something less ambitious than a full-blown GUI app (which I think is a good idea), it's hard get a grasp on concepts like laziness, recursive datatypes, parametric polymorphism, monads, type classes and so on in less than a week, even for experienced programmers. At best, I imagine you'll come away curious and hungry for more; but clearly that doesn't suffice for a "language evaluation". Of course, the fact that Haskell can't be grasped in a day (or week) can be construed as a practical argument against its adoption. On the other hand, if you accept that there's no such thing as a free lunch, you might consider that a merit; what is the point of adopting a new language if it doesn't change the way you think about programming, and let you write old programs in new, perhaps better, ways? [1] While Haskell is IMO the best programming language around, and I want to encourage its broader adoption, if you want a well-designed language with good implementation and support which permits swifter skill transfer, may I (strongly) recommend you add Objective Caml to your list of candidates? Once you acquire some experience with an ML-like language such as OCaml, which after all resembles Haskell in many ways, you will, I believe, find yourself better equipped to evaluate Haskell. Regards, Frank [1] Think about polynomials and real numbers. Complex numbers were, I believe, invented specifically to ensure that every polynomial equation has a solution. So, to address some problems, we need to take a step backward before we can take one forward.

On Wed, 5 May 2004, Frank Atanassow wrote:
Frankly, I think it's completely unrealistic to expect to be able to fairly evaluate Haskell in 32 hours. As you noted yourself, Scheme and Erlang, being strict, are much closer to conventional programming languages than Haskell is, so it's easier to transfer skills to them.
Yeah, I'm starting to see the difficulty in recommending a language I can barely dabble in up the chain (not as bad as pointy hair bosses, but still not computer scientists).
Furthermore, they're untyped, and learning how to exploit Haskell's static typing is one of the bigger hurdles to learning how to exploit Haskell.
That was one of the things that attracted me to Haskell...the type system. I enjoyed strong typing in ML when I played with it in college.
At best, I imagine you'll come away curious and hungry for more; but clearly that doesn't suffice for a "language evaluation".
Certainly.
Of course, the fact that Haskell can't be grasped in a day (or week) can be construed as a practical argument against its adoption. On the other hand, if you accept that there's no such thing as a free lunch, you might consider that a merit; what is the point of adopting a new language if it doesn't change the way you think about programming, and let you write old programs in new, perhaps better, ways? [1]
This is the crux of the argument. I don't understand how we can make good programming languages more popular. My son was born just a couple of weeks ago, and I barely have enough time now to keep up with anything in my career/field; I was lucky I convinced my management to let me do a (too-) brief language survey. But without having "thought" in Haskell for at least a couple of months, how can I hope to promote it successfully? How can I get a couple of months proficiency in Haskell unless I've promoted it successfully? (Co-routines? =)
While Haskell is IMO the best programming language around, and I want to encourage its broader adoption, if you want a well-designed language with good implementation and support which permits swifter skill transfer, may I (strongly) recommend you add Objective Caml to your list of candidates? Once you acquire some experience with an ML-like language such as OCaml, which after all resembles Haskell in many ways, you will, I believe, find yourself better equipped to evaluate Haskell.
Thanks for this...I actually just added ocaml to my list last night. I was looking over the "programming languages shootout" and read some of the source. It looks pretty neat. I spent last night writing a simple object system from scratch in Scheme with macros, and starting thinking about all the things I'd have to do to implement any kind of type safety, and it just sort of clicked that ocaml might be an interesting solution. Thanks again for your comments (and everyone's). -- Mike J. Bell This is all just my opinion. "Outside of a dog, a book is man's best friend. Inside it's too dark to read." mikeb@manor.org

Faced with trying to climb Haskell's (steep!) learning curve, I wrote a simple (in-memory) rdbms in under 1000 lines of code (something I will use anyway if I eventually adopt Haskell as the implementation language for my prospective app). http://www.alexjacobson.com/archives/2004_04.html#000046 http://www.alexjacobson.com/archives/2004_04.html#000047 Being able to do that certainly impressed me! OTOH, it occurs to me now that another approach might have been to try and read/understand/modify an existing Haskell program in the category of your intended app. I think someone wrote a book about multi-media apps in Haskell (I've seen a chapter somewhere from Conal Elliot) but I don't remember what it was. -Alex- _________________________________________________________________ S. Alexander Jacobson mailto:me@alexjacobson.com tel:917-770-6565 http://alexjacobson.com On Mon, 3 May 2004 mikeb@manor.org wrote:
Hi folks,
I've got an interesting task this week for my job. (Note that this will undoubtably last for longer than a week). I'm evaluating several high-level languages as development vehicles for our next suite of applications. The languages I'm currently considering are Scheme, Erlang, and Haskell.
Scheme and Haskell have fairly wide acceptance in their particular roles (Scheme as the "pretty" lisp, supporting higher-order functions and mostly strict [until you roll your own laziness with macros], and Haskell the absolute purest language with no side effects and fully lazy evaluation). Erlang has a really nice distributed computing model, and has a nice union of non- and side-effect qualities (although it's completely strict).
The toy application I've "designed" for myself is a simple GUI-based app that can load a Sun .au format sound file, display its waveform in a window, perform some simple filtering, play the sound for the user, and then save the changed sound file back out to disk. If I get familiar enough with the respective environments I'd like to add zooming in/out and scrolling to the waveform display.
This application should allow me to see all kinds of different characteristics of the language/implementation, such as performance (how fast can the filter run), I/O (how fast can I load/save data to disk), OS interaction (how easy can I "play" the audio), user acceptance (how easy is it to do GUI programming) and of course the software engineering goals of modularity, correctness, and simplicity.
The end goal is for me to have three working programs, in three different languages, so that I can present to my boss the performance/software engineering characteristics of each system to choose our next development language.
So I'm writing you to solicit help. I have an amortized four days (32 hours!!!) to implement this simple application in Haskell. Can anyone point me to example code, supporting libraries, tutorials, etc. that are in this area of development? If I have to dumb down some of my application in order to make a great discovery about a language, that's fine. I'm expecting some great differences between these three programs.
Any advice/pointers/flames welcome. Thanks in advance.
Mike
-- Mike J. Bell This is all just my opinion. "Outside of a dog, a book is man's best friend. Inside it's too dark to read." mikeb@manor.org _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On May 6, 2004, at 6:59 PM, S. Alexander Jacobson wrote:
I think someone wrote a book about multi-media apps in Haskell (I've seen a chapter somewhere from Conal Elliot) but I don't remember what it was.
Probably Paul Hudak's "The Haskell School of Expression". http://www.haskell.org/soe/ I had forgotten about this; maybe the soundwave GUI app idea is not so unrealistic? I haven't read SOE, but my impression is that it comes with a simple graphics library, and an on-topic book might get a novice up to speed quickly. Regards, Frank

Sound on linux tends to center around the "jack" sound architecture. This is a demon for connecting audio and midi gadgets as it were by jack-leads. From a brief look, it seems very callback oriented. It seems to be highly thought of by knowledgable audio types, and the bee's knees for low latency. It could be fun to figure out ways of writing jack-clients and plugins in Haskell. Would it be difficult, or stupid? Are callbacks to Haskell from C a problem? I suppose an interesting jackable component written in Haskell would of necessity something more midi than audio oriented. Peter Hancock

It could be fun to figure out ways of writing jack-clients and plugins in Haskell. Would it be difficult, or stupid? Are callbacks to Haskell from C a problem?
Callbacks to Haskell are very easy using the ffi extension supported by Hugs, GHC and NHC. If components are standalone apps, that's all you need to do. If components are more like libraries, you'll need to take care of initializing the Haskell runtime, etc. (The ffi has calls to do this though I think only GHC implements them.)
I suppose an interesting jackable component written in Haskell would of necessity something more midi than audio oriented.
Because of raw performance or GC delays? 1) Performance If you take just a little care, GHC can generate some pretty fast code and generating 88 thousand samples per second (i.e., CD-rate stereo) isn't really that much on your typical PC hardware. Or, if you want to be able to use Hugs or GHC just isn't fast enough, you could write the inner loop in C and use Haskell to control how it is invoked. (I'm assuming that most audio ops can be expressed in terms of a few generic convolution operators.) We had good luck with this sort of approach at Yale when doing real-time visual tracking. (The important things to know about visual tracking are that you process megabytes of data per second and the more frames per second you can process the more reliable the tracking.) The 'inner loop' was written in C or hand-bummed assembly code and the rest was written in Haskell. Performance was something like 99.9% of equivalent C code. 2) GC delays. GC systems are usually tuned to minimise overhead but can usually be persuaded to minimise the average or worst delay by specifying different sizes of different allocation arenas and explicitly invoking the garbage collector. Again, this is something we did at Yale with the visual tracking. You'd probably do very well with a simple policy like invoking the GC N-times per second of sound processed. -- Alastair Reid

Sound on linux tends to center around the "jack" sound architecture. This is a demon for connecting audio and midi gadgets
the problem with os-specific solutions is that they, and code based on them, don't work on other platforms - reduces the target audience and the potential gain for anyone wanting to invest time. for graphics, we've got OpenGL, and a nice Haskell binding to it, so I wonder whether there's a similar option for sound? e.g., does anyone have experience with PortAudio/PortMusic/PortMidi? PortAudio - portable cross-platform Audio API (platforms including Windows, Macintosh (8,9,X), Unix (OSS), SGI, and BeOS) http://www.portaudio.com/ PortMusic APIs - Platform Independent Libraries for Sound and MIDI ( PortMusic is open-source and runs on Windows, Macintosh, and Linux. Currently, libraries support Audio I/O and MIDI I/O) http://www-2.cs.cmu.edu/~music/portmusic/ would that be a useful basis for a portable Haskell sound binding? or has anyone already implemented such bindings, for this or any other sound API (SOE's music component includes Midi file support, and also talks about csound)? cheers, claus ps. just had a look at their mailing list archives, and saw a reply by Roger Dannenberg, confirming that PortMidi is still being developed http://www.create.ucsb.edu/pipermail/media_api/2004-May/000305.html (given his background in functional real-time control and music languages, he should be interested if anyone wanted to provide a Haskell binding!-)

On Fri, 7 May 2004, Claus Reinke wrote:
for graphics, we've got OpenGL, and a nice Haskell binding to it, so I wonder whether there's a similar option for sound? e.g., does anyone have experience with PortAudio/PortMusic/PortMidi?
Looking over the PortAudio specs it's good for a software processing environment but not a lot of use to eg a game. OpenAL appears to be much the other way round. -- flippa@flippac.org

Looking over the PortAudio specs it's good for a software processing environment but not a lot of use to eg a game. OpenAL appears to be much the other way round.
The thing that always confused me about OpenAL (www.openal.org) is the following part of the spec: OpenAL Fundamentals OpenAL (henceforth, the "AL") is concerned only with rendering audio into an output buffer, and primarily meant for spatialized audio. There is no support for reading audio input from buffers at this time, and no support for MIDI and other components usually associated with audio hardware. Programmers must relay on other mechanisms to obtain audio (e.g. voice) input or generate music. other potential options, depending on intended use: Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. http://www.libsdl.org/ MidiShare is a musical operating system for Macintosh (MacOS Classic and MacOSX), Windows 3.1, Windows 95/98, Windows NT/2000/XP, Atari and Linux. Result of many years of research and development undertaken by Computer Music Research Laboratory of Grame, MidiShare provides high level services to the field of computer music and MIDI applications. http://www.grame.fr/MidiShare/ others? cheers, claus

Claus Reinke wrote:
The thing that always confused me about OpenAL (www.openal.org) is the following part of the spec: [...]
The basic ideas behind OpenAL are quite easy and centered around 3 concepts: * Buffers containing (normally mono) audio data, which can be shared by sources (see below). This is where you put e.g. your WAV data. * Sources generating (perhaps directed) sound at a point in 3D space for the queues of buffers attached to them. These correspond to sound emitting entities in your virtual 3D world, e.g. enemies shooting at you. :-) * A single listener (= you) positioned at a point in 3D space. OpenAL renders the sound to your audio device (stereo headphones, 5.1 speakers, etc.) via a lower device layer (ALSA, DirectSound, etc.). It doesn't handle MIDI, but there are e.g. extensions for microphone input. The "spirit" of OpenAL is very much like OpenGL, and both fit quite nicely together, although you can use each of these libraries on their own. It works on all major platforms (WinDoze, Linux, MacOS X, ...) and is an "industrial-strength" library, meaning that even people who make their living from programming use it, see e.g. Unreal Tournament 2004 and quite a few other commercial games. A few months ago I started an OpenAL binding for Haskell, see the fptools repository at fptools/libraries/OpenAL. The basic functionality is there, but the binding is not complete yet. The main reason for the latter is that I couldn't get my 4.1 speakers working under my previous SuSE Linux, but I've just upgraded, so hopefully things have improved and the binding can be finished. Apart from that, having a binding for SDL would be nice, too, and somebody is already working on it, IIRC. Cheers, S.

On Saturday 08 May 2004 12:16 pm, Sven Panne wrote:
Apart from that, having a binding for SDL would be nice, too, and somebody is already working on it, IIRC.
Urrm, that would be me I think:-) Though in the context of this discussion I have to warn that so far I have ignored the audio features of SDL. I know when we discussed this a few weeks ago I thought a first release was close, I'm afraid I still haven't finished polishing it yet as I've been a bit busier than I expected with other commitments. (Having to earn money is a tiresome distraction from Haskell programming :-) But if anybody wants it "as is" I can email what I have. Regards -- Adrian Hey

For what it's worth, SOE and Haskore provide support for reading and writing MIDI files, and for generating both score and orchestra files in csound. But there is no direct support for sound files, nor is there support for real-time MIDI. -Paul Claus Reinke wrote:
(SOE's music component includes Midi file support, and also talks about csound)?
participants (12)
-
Adrian Hey
-
Alastair Reid
-
Claus Reinke
-
Duncan Coutts
-
Frank Atanassow
-
hancock@spamcop.net
-
mikeb@manor.org
-
Paul Hudak
-
Philippa Cowderoy
-
S. Alexander Jacobson
-
Sven Panne
-
Vincenzo aka Nick Name