Functional Programming for Parallelism and Concurrency

- March 2, 2014
Kwang's Haskell Blog - Functional Programming for Parallelism and Concurrency

Functional Programming for Parallelism and Concurrency

Posted on March 2, 2014 by Kwang Yul Seo

One reason why functional programming is gaining more attentions from main stream developers is that it is a promising technology which might solve so called “PPP (popular parallel programming) grand challenge”.

Our current situation looks doomed. Moore’s law is being achieved by increasing # of cores not clock cycles and huge volume workloads requires horizontal scaling. We are hopeless because mutable states in imperative programming combined with parallel processing result in non-determinism and it is not easy to cope with non-determinism in programming.

One possible way to solve this problem is to avoid mutable states. There is no non-determinism without mutable states. There is no race condition or dead lock without mutable states. Mutable states are the root of the problem. Martin Odersky explained how functional programming can solve this problem in his OSCON 2011 Java keynote presentation.

Oscon keynote: Working hard to keep it simple

Read more

Evaluation Strategy: Haskell vs Scala

- March 2, 2014
Kwang's Haskell Blog - Evaluation Strategy: Haskell vs Scala

Evaluation Strategy: Haskell vs Scala

Posted on March 2, 2014 by Kwang Yul Seo

Haskell is a non-strict language, and GHC uses a strategy called laziness which combines non-strictness and sharing for efficiency.

Thus, you can easily implement const which never uses the second argument.

const x y = x

With this definition, it is okay to pass undefined as the second argument of const because y is not never evaluated. But in Haskell, you can also make an argument strict using the BangPatterns GHC extension.

const x !y = x

Interestingly, the situation is reversed in Scala whose default evaluation strategy is strict.

def const(x: Int, y:Int) = x

You can make an argument non-strict by putting the => symbol between the variable name and the type.

def const(x: Int, y: => Int) = x
Read more