- Example 1: factorial
- Example 2: map
- Example 3: join
As a rookie Haskeller coming from imperative languages I am still
often shocked how elegantly mathematical problems can be expressed in this
great language. Last time a wrote a blogpost about recursion.
As an example, I presented the
Relation
type and implemented an operation to it I called join
. If you are
familiar with relational algebra you might have recognized that this is a
specific case of equijoin
,
where you join pairs so that the first pair's second element matches the second
pair's first element.
I was thinking about a more complex problem I could solve with this toolkit, one
We all know about the Fibonacci sequence. Some of us also know a song that uses it to achieve a spiraling feeling (yes, Tool fans!).
In Haskell:
fib 1 = 0
fib 2 = 1
fib x = fib (x - 1) (x - 2)
'use strict' | |
var crypto = require('crypto') | |
var promise = Promise.resolve() | |
var data = [] | |
for (var i = 0; i < 1e5; ++i) { | |
promise = promise.then(function () { | |
return new Promise(function (resolve, reject) { |
#!/usr/bin/env node | |
'use strict' | |
var mysql = require('mysql') | |
var fs = require('fs') | |
var path = require('path') | |
function exitOnError (f) { | |
return function (err) { |
data Day = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday | |
deriving (Eq, Ord, Show, Read, Bounded, Enum) | |
-- and that's it. we have everything we need | |
-- david@mac:~% stack ghci | |
-- λ> Monday == Tuesday | |
-- False | |
-- λ> Monday == Monday | |
-- True | |
-- λ> Tuesday > Monday |
{-# LANGUAGE NoImplicitPrelude #-} | |
module Rng where | |
import GHC.Show (Show) | |
import GHC.Base (Eq, ($)) | |
import GHC.Num ((*), (+), Integer) | |
import GHC.Float (Float, Double) | |
import GHC.Real (fromIntegral, (/)) | |
import GHC.Enum (maxBound) | |
import Data.Int (Int64, Int32, Int16, Int8) |
// Turn a generator function into a coroutine | |
const coroutine = (f) => (...args) => { | |
const g = f(...args) // instantiate the generator | |
const iter = ({ done, value }) => done // iterate over suspensions | |
? value | |
: value.then( | |
(d) => iter(g.next(d)), | |
(e) => iter(g.throw(e)) | |
) | |
return Promise.resolve().then(() => iter(g.next())) // start iterating asynchronously |
Abstract: Blogpost summarizing the challenges of creating a flexible and customizable MIDI controller mapping for Mixxx targeting multiple Novation Launchpad grid controllers.
Keywords: JavaScript, MIDI, Mixxx, ES6 modules, Babel, Flow
I own two Novation Launchpads. The most iconic use-cases of this cool grid controller is launching samples. Launchpad cover videos are very popular on YouTube. These are done by slicing up the songs, and playing back live, spiced with some flashy visual effects.
You can also use launchpads for DJing. While being fit for a handful of things: cueing samples, beatjumping and looping, etc.; the Launchpad have neither a jogwheel nor any rotary controls or faders, so it falls short on functions like scratching or crossfading. Thus, it’s best to use as companion to your other DJ gear.
/* Copyright 2017 David Szakallas, MIT License */ | |
import simulacrum.{op, typeclass} | |
@typeclass trait GenKleeneLike[-A] { | |
@op("|=|") def eq(x: A, y: A): Option[Boolean] | |
@op("|!|") def ne(x: A, y: A): Option[Boolean] | |
} | |
object GenKleeneLike { | |
class GenKleeneLikeForOption[Opt <: Option[Any]] extends GenKleeneLike[Opt] { | |
override def eq(x: Opt, y: Opt): Option[Boolean] = |