TypeClasses:
Filter:
FPLib/Classes (extension) | FP

TypeClasses
ExtensionExtension

Haskell style type classes

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 is http://learnyouahaskell.com/. The library is also very much inspired by ScalaZ: https://github.com/scalaz/scalaz

NOTE: SuperCollider does not curry functions by default, so if a type class instance function requires a curried function this should be done manually. A 'curried' method was introduced for this. For applicative functors, <%> automatically curries the function.

The type anotations use the scala syntax and are there just so you know what the function should return. It's up to the user to make sure the functions return the correct class, if they do not, an error will be thrown at runtime.

Functor

requires implementation of:

fmap is equivalent to the collect method of the sc collections.

Applicative Functor

requires implementation of:

Applicative functors essentially generalize Functors for functions of a more than one argument. The method name <$> could not be defined in SuperCollider so we use instead <%>

Let's say you have 3 objects of the Option class, a,b and c, and you want to run a function f of 3 arguments only if all of the three objets are a Some, then you can do:

if a = Some(a'), b = Some(b') and c = Some(c'), this will return Some(f.(a',b',c')) otherwise it will return None().

Monad

requires implementation of:

The bind operator for arrays acts as performing multi-value computations.

Monads are not so usefull for Arrays, they are quite more interesting for Option and Writer, Reader and State classes (which are not yet implemented).

Traverse

requires implementation of:

makes available:

According to this blog post[1] Traverse generalizes a for loop with functional code. It is based on the paper "The Essence of the Iterator Pattern"[2].

Double traversal:

State depends on elements and elements depend on state: