Home > news > [news] FP Quarks from Miguel Negrao for Supercollider

[news] FP Quarks from Miguel Negrao for Supercollider

From author:


I’m officially releasing the FP quark. It contains an assortment of Functional Programming related bits of code:

– Type Classes –  From the help:

This is an experimental implementation of Haskell style type classes for supercollider. The library relies heavilly on the concepts of Monad, Functor, Applicativer Functor, etc, so it is advised to read up on these topics. A good source ishttp://learnyouahaskell.com/. The library is also very much inspired by ScalaZ: https://github.com/scalaz/scalaz
SC is a dynamic language, it does not have typed functions, therefore this adaptation of the Haskell type classes, which as the name suggests, rely on types, might not always make sense. The type classes are implemented using dictionary look ups for the correct function to use. This might introduce a bit of overhead, so use with caution, specially for large data structures or when repeating the same function evaluation many time per second.

Type instances for your own classes should be added in the initClass method. Have a look at EventSource to see how to do it.

– Functional Reactive Programming Library –  EventStreams and Signals. Very useful for dealing with events and propagation of change in all sorts of contexts such as with controllers (Modality library), GUIs, etc. See the overview help file.

– “I.d” an alias for the identity function and “Unit” a data type to be used as the return value by functions that perform side-effects and don’t return any value.

– Option data type, i.e,  Some(3) or None (equivalent to Just 3 or Nothing in Haskell).

– IO monad – for the brave souls wishing to go into pure functional programming.

– For comprehensions – as seen in scala. Unfortunately we can’t have the nice syntax of scala, so it’s of limited (no ?) use.

I plan to add soon an immutable collection based on FingerTrees which gives good performance for searching for items in the middle of the list, cutting and joining the list, etc (compared to an immutable list implemented in sclang) while always returning a new collection (never mutating anything). Unfortunately because it’s completely coded in sclang it is 1000x slower then an array for some operations. To be used only with small arrays in non time sensitive situations.

Miguel Negrão

Quarks repo: http://quarks.sourceforge.net/

Categories: news Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: