I hereby claim:
- I am dszakallas on github.
- I am david_szakallas (https://keybase.io/david_szakallas) on keybase.
- I have a public key whose fingerprint is 38F9 8FCE 7CED FA3C 04D9 B6FE 9E63 257F 2A73 97BB
To claim this, I am signing this object:
a |
I hereby claim:
To claim this, I am signing this object:
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)
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
Recently I've been writing a graph query engine at Fault Tolerant System Research Group at uni. The frontend is Cypher, a language popularized by Neo Technology shipped OOTB with their graph database Neo4j.
Recently Cypher is getting standardized in an open source and open government initiative under the name openCypher; and other DB vendors, such as the RDBMS giant Oracle are starting to support it.
The language itself is similar to SQL augmented with syntax for graph pattern matching. One of the similarities is the handling of NULL values.
// 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 |
Disclaimer: This is a satire, and not meant to be taken any more seriously than Java itself. It is not about Java 8 streams. This satire just shows how easy is to define a very complex endless stream functionally in Java using lambdas.
In Scala:
def naturals: Stream[Int] = 0 #:: naturals.map(_ + 1)
(ns my-first-clojure-go-routine | |
(:require [clojure.core.async :refer :all])) | |
(defn ping [name chan & [start?]] | |
(go (when start? (>! chan 0)) | |
(loop [i (<! chan)] | |
(println name i) | |
(>! chan (inc i)) | |
(if (< i 100) (recur (<! chan)) i)))) |