mathr / blog / #

Haskell code in Pd object boxes

So I was washing dishes, and my mind wandered. hsext development is somewhat on hiatus at the moment, while I think about the best way to rewrite it in a way that doesn't suck quite so much. I still want to be able to load Haskell code from files, but my new thought is that it would also be cool to write little snippets of Haskell directly in object boxes. Having thought about this some more, while my hands were disconnectedly scrubbing mugs, I've reached some conclusions.

Firstly, Haskell is statically typed, by which I mean the type of everything is fixed before you compile and run the code. This creates difficulties if you want to dynamically compile and run code on the fly, because you could end up with a type of value you don't know how to deal with.

Moreover, when you create an object box in Pd, it takes the first atom of the list to be the name of the object class to create. So we need a class name for the "Haskell code in object boxes" class.

Noting this, I started to think of a way to resolve both of these issues in an elegant way. Haskell has a type inference system that lets you avoid having to write types everywhere, but when you want to annotate a value with a type, the notation is something like this:

value :: TypeA -> TypeB -> TypeZ

The value above can be seen as a function that expects an A and a B and gives you a Z.

So, I think I'll call the "Haskell code in object boxes" class ::, and use it like this:

:: Float -> Float -> Float;

(+)

or:

:: Float -> Float -> (Float, Float);

L a b -> (a `min` b, a `max` b)

or:

:: [String] -> String -> String;

L as b -> (concat . intersperse b) as

How to marshall Pd messages into Floats and Strings is a topic for another day.

...

Meanwhile, I got sidetracked toying with Arrows. Wondering whether code like the following is anyway reasonable...

cuu o f g = curry (uncurry f `o` uncurry g)

(&&&&) = cuu (&&&)

(>>>>)= cuu (>>>)

((max &&&& min) >>>> ((-) &&&& (/))) 6 66 -- (60.0, 11.0)