FPLib
FPLib
Functional Programming library for SuperCollider
Requirements
- SuperCollider 3.9.3
- JITLibExtensions quarks.
- Modality Library
Instalation
Move this folder to the SuperCollider 'Extensions' folder.
Overview
Making full use of this library requires knowledge of modern Functional Programming concepts as implemented for instance in Haskell, specially familiarity with functors, applicative functors, monoids and monads.
I recommend reading a book such as "Learn you a Haskell for greater good".
The Library implements an experimental type class system, where the functions of the type classes are defined in Object and to "implement" a type class a SuperCollider class has to overload the corresponding functions (i.e. >>= or collect). This doesn't allow for more advanced uses of type classes but allows defining functions that are available to a specific type class, by defining a corresponding method in Object (i.e. sequence depends on traverse, >>=| depends on >>=). If one calls >>=| on a class that is not a monad (doesn't implement >>= ) an error is thrown. Some methods such as sequence cannot be used like in Haskell because SuperCollider doesn't have the sophisticated type system to infere the right class to use in some circunstances. In those cases o type hint must be given:
[].sequence(Option)
Without this type hint, there would be no way to know in what class to wrap the empty array.
Type Classes:
Functor
- needs: collect
Applicative Functor (AF):
- needs:
<*>
,*makePure
- makes available:
<*
,*>
,<%>
,sequence
,pure
Monad
- needs:
>>=
,*makePure
(we don't distinguish between AF's pure and Monad's return) - makes available:
>>=|
,sequenceM
,pure
Monoid
- needs:
|+|
,*zero
Traverse
- needs:
traverse
- makes available:
collectTraverse
,disperse
Instances of Type Classes:
- IO
- Option
- Validation
- Promise
- Reader
- ST
- WriterReader
- RWST
New collections:
- LazyList
- Tuple(n)
Functional Reactive Programming
Classes:
FPSignal
, EventStream
and their children.
These classes are based on scala and haskell implementations of FRP.
A monad for constructing the event processors graph is available which is compiled into a EventNetwork
which can be started and stopped at will. The network description itself has this pseudo type:
//networkDescription : Writer( Unit, Tuple3([IO(IO())], [EventStream[IO[Unit]]], [IO] ) )
// eventHandlers reactimates IOLater
More info
See the help files, including the reference page, the examples directory and also there are some blog posts relating to FP Lib at http://www.friendlyvirus.org/miguelnegrao/category/code/.
ace76753f39389697b9c02c838fe004a02cad433
1b0f74ec9bc51deec1e7290a5bbb63c3c3930d9d
d5563fd110930cf5686510e54016639d2eba643b
Installation
Repository
URL
https://github.com/miguel-negrao/FPLib
Since
2012-03-12
Last update
2021-01-18
Current version
v0.2.1
Quark info
name
FPLib
schelp
FP Lib
license
GPL3
summary
Functional Programming library for SuperCollider
version
0.3.1
copyright
Miguel Negrão 2012-2018
dependencies
['JITLibExtensions', 'Modality-toolkit']