2

I'm considering a functional language that will play well with my environment of C/Objective-C under FreeBSD, OSX, iOS. It looks like my best bet is to create functional-language libraries for specific functions, written in Haskell, compile with GHC, and use FFI to call this functional code as a standard C call.

My question is, how do I handle concurrency in this situation? One motivation for using a functional language is that for my problems where I want to operate on immutable datasets, I want to get a lot of parallelization going. However, using the approach I detail here, will I get ANY parallelization? It appears I can compile and dictate to use 2 threads, but is there any way to use GCD instead of threading (for all the reasons GCD is better than threads, such as the amount of parallelization automatically scaling per-platform)? Or, going with FFI as I describe, do I completely lose the ability to multithread?

This language seems like the best match for what I'm trying to do, but I want to learn if it's the right fit before I devote a significant amount of time to truly learn it

Don Stewart
  • 137,316
  • 36
  • 365
  • 468
Nektarios
  • 10,173
  • 8
  • 63
  • 93
  • You might have a look at Erlang for parallel and distributed functional programming. – Peer Stritzinger Apr 03 '11 at 18:21
  • 1
    You need to spell out lots more details -- what sorts of apps are you developing? What sorts of functions are you hoping to write in Haskell vs. C? What level of parallelism do you want to exploit? – sclv Apr 03 '11 at 19:18

1 Answers1

2

GHC's runtime replaces the need for GCD, doesn't it? And it already provides cross-platform parallelism.

Don Stewart
  • 137,316
  • 36
  • 365
  • 468
  • Does it? How exactly? What is this called so that I can find more information about it? And when I'm using the fully compiled and statically linked w/runtime GHC output in my code, does this parallelism happen without any intervention on my part? – Nektarios Apr 03 '11 at 19:10
  • 1
    GHC provides a rich runtime system supporting [many parallel and concurrent programming models](http://stackoverflow.com/questions/3063652/whats-the-status-of-multicore-programming-in-haskell). The primary mechanism for gaining parallelism is via [explicit threading and locks](http://book.realworldhaskell.org/read/concurrent-and-multicore-programming.html), though you may consider the use of STM instead of locks, or other parallel mechanisms (such as sparks, data parallelism or the Par monad). – Don Stewart Apr 03 '11 at 19:18
  • When you initialize the runtime, you can pass it options including the number of capabilities to use: http://www.haskell.org/ghc/docs/7.0.2/html/users_guide/ffi-ghc.html#using-own-main – sclv Apr 03 '11 at 19:22
  • just wanted to reiterate that I read a presentation you made and I found it very enlightening and this looks like it does answer the mail fully. Thank you – Nektarios Apr 04 '11 at 17:47