Mehr Nächster Blog» Blog erstellen Anmelden Diese Website verwendet Cookies von Google, um ihre Dienste bereitzustellen, Anzeigen zu personalisieren und Zugriffe zu analysieren. Informationen darüber, wie du die Website verwendest, werden an Google WEITERE INFORMATIONEN OK weitergegeben. Durch die Nutzung dieser Website erklärst du dich damit einverstanden, dass sie Cookies verwendet. The Flying Frog Blog

Monday, 30 May 2016 Disadvantages of purely Links

I have been asked to elaborate on my answer on Quora so here Visual F# 2010 for Technical Computing goes: (book) The F#.NET Journal (on-line magazine) The OCaml Journal (on-line magazine) F# for Numerics (library) 1. There is no efficient purely functional unsorted dictionary F# for Visualization (library) or set OCaml for Scientists (book) FFT .NET (library) Since the 1990s the use of dictionaries in software has gone Time-Frequency Analysis (Mathematica through the roof. Dictionaries are now a stock collection type that library) every programmer expects to find in their standard library. High-Level Virtual Machine (HLVM) Smoke Vector Graphics (OCaml library) Purely functional or persistent data structures such as those found in Okasaki’s fabulous monograph on the subject can be a great tool. In particular, the persistence they offer means you can reuse old versions of collections without having to worry about mutation. Popular Posts In many cases (particularly for some kinds of problems such as logic programming and compiler writing) this can make solutions Disadvantages of purely functional shorter and clearer, partly because it makes backtracking trivial. programming However, persistence comes at a great cost in terms of I have been asked to elaborate on my performance: purely functional dictionaries are typically 10x slower answer on Quora so here goes: 1. than a decent hash table and I have seen them run up to 40x There is no efficient purely functional unsorted dictionary o... slower. For some applications this is just too slow. Why is Haskell used so little in the Furthermore, most functional programming languages (OCaml, industry? Haskell, Scala) are incapable of expressing a fast generic mutable Bugspy asked an interesting question on hash table because they lack the killer combo of: reified generics, Stack Overflow recently: It is a wonderful, value types and a fast GC write barrier. very fast, mature and complete language. It exists fo... BEWARE: people who try to claim that Haskell’s purely functional dictionaries are fast by comparing them with Haskell’s mutable Are functional languages inherently slow? Functional languages require infrastructure hash tables. The correct conclusion is that Haskell’s mutable hash that inevitably adds overheads over what tables are slow. can theoretically be attained using assembler by hand....

F# vs OCaml vs Haskell: hash table 2. There is no purely functional weak hash table. performance I just stumbled upon an interesting With a garbage collected imperative language, the relationships benchmark. Put mappings i -> i for i in between the vertices and edges of a graph can be expressed using 1..10M in a hash table, print the entry for weak hash tables. The garbage collector will then collect 100. Don Stewart&... unreachable subgraphs for you. There is no purely functional weak Boost's shared_ptr up to hash table so, in a pure language, you must write your own 10× slower than OCaml's garbage collector. garbage collection Our recent post about the Note that this is a really fringe disadvantage with most developers merits of accurate garbage never having used a weak hash table! collection over reference counting prompted Tezka to ask for measurements demonstratin...

3. There are no purely functional concurrent collections. The rise and fall of OCaml After over 3 years, The By definition, immutable collections cannot support concurrent OCaml Journal is finally closing down. New mutation. Consequently, if you want a shared mutable collection subscriptions offer access to such as an in-memory database then there is no efficient purely the 75 existing articles and functional solution. only a few mo...

The "++ renaissance" According to Herb Sutter, 4. Most graph algorithms look worse and run much slower C++ (and C and Fortran) when written in an FP style. are unmatched for performance per dollar and, Purely functional programming is a great tool for some kinds of therefore, he believes C++ will once again t... problems but graph algorithms are one place where I have noticed

that pure solutions are often worse both in terms of speed and Memory management myths: promptness clarity. People often assert that -based reference counting such as shared_ptr in Compare Prim’s algorithm in 12 lines of Python with Prim’s C++ collects garbage “promptly” and algorithm in 20 lines of Haskell. And why does the Haskell use some people define this... Prim’s algorithm? Probably because Kruskal’s algorithm is built upon the union-find collection and there is no known efficient Are multicore-capable garbage collectors hard to write? purely functional union-find collection. In this era of multicore computing, garbage collectors need to allow user threads (aka mutators ) to run in parallel on separate cores simul... 5. The inertia of traditional imperative data structures and algorithms is huge. Mono 2.2 vs OCaml vs .NET vs LLVM vs JDK Beyond graph algorithms, there are many parts of computer Mono 2.2 was recently science where 65 years of published literature has focused almost shipped and a new JIT code entirely upon imperative solutions. Consequently, imperative generator was the main selling point promoted by programmers can easily build upon the backs of giants whereas the Mono project because it provides the purely functional programmers are often left starting from scratch. ... After all, just a few years ago memoization in Haskell was the topic of a PhD thesis!

I once challenged a group of Haskell programmers (several of Follow by Email whom had PhDs in Haskell) to write an efficient generic parallelised quicksort in Haskell and this is what happened. Email address... Submit

6. All existing implementations of functional programming Related Blogs languages, both pure and impure, happen to allocate far too much by design. F# News Fractal Explorer - The F# Journal just Around 1960, McCarthy invented Lisp. The core data structure was published an article about parsing: *"A the singly-linked list. Each list node was a separate heap allocated fractal is a mathematical set that exhibits a self-repeating structure at block. All modern functional languages evolved from this. In the arbitrary scales and s... 1970s, Scheme used essentially the same data representation 3 weeks ago strategy as Lisp. In the 1980s, SML added a little unboxing with tuples heap allocated as a single block of memory. In the 1990s, OCaml added a little more with unboxed float arrays. Haskell added Subscribe the ability to unbox some data. But to date no functional programming language has unboxed tuples by default. Even F#, Posts which sits on .NET which provides arbitrary value types, still uses .NET’s boxed tuples. Consequently, all modern functional Comments programming languages incur very high allocation rates for essentially no good reason. Consequently, they all stress their garbage collectors far more than necessary. This is a serious Blog Archive problem not just because it makes serial code slow but because the garbage collector is a shared resource and, therefore, stressing the ▼ 2016 (3) GC impedes the scalability of parallel programs. ▼ May (2) Disadvantages of purely functional I should note that calling this a “disadvantage” is contentious. programming Xavier Leroy of OCaml fame regards OCaml’s Lisp-like data ARM code generation quality representation as a good thing because it is the backbone of ► January (1) OCaml’s excellent performance when running the Coq theorem ► 2015 (5) prover. Here Xavier asserted that “OCaml's strategy is close to ► 2014 (1) optimal for symbolic computing”. Functional languages are often ► 2013 (10) optimised for high performance purely functional collections at the ► 2012 (23) expense of low performance imperative collections. Given that ► 2011 (16) imperative collections are generally faster, this puts an artificially- ► 2010 (53) low ceiling on the performance of almost all functional languages. ► 2009 (28) ► 2008 (10) ► 2007 (21)

7. Purely functional programming is theoretically good for parallelism but bad for performance in practice, which is the Labels sole purpose of parallelism.

There are two reasons to write parallel programs today. The first is .net (5) to write objectively fast solutions. The second is to make a slow academic (1) solution less slow. In most cases, parallel programming in accumulator generator (1) functional languages is a form of the latter. Almost nobody in high advantages (1) performance computing circles (i.e. supercomputers) is running allocation (1) functional code directly. When most functional programmers amd (1) employ parallel programming today they do so not to attain the amorphous (1) analysis (1) best absolute performance but just to improve the performance animation (1) they have. API (1) Purely functional languages like Haskell are designed to abstract apple (2) away space and time. This gives you a higher-level perspective of arm (3) your solution but it makes it very hard to reason about the amount array (1) articles (1) of memory or length of time a Haskell program will require to asynchronous (2) produce a result. In parallel programming it is always important to asynchronous workflow (1) make sure that the gain from parallelisation outweighs the beginner (1) administrative overheads of running code in parallel. Haskell makes Beltway (1) this very hard. So hard, in fact, that published research on parallel benchmark (5) Haskell notoriously cherry picks the degree of parallelisation that bfg (1) maximises performance even though that degree could not be bitvector (1) predicted before running the program many times. I have found bitwise (1) that straightforward parallelization often yields reliable speedups in bjarne stroustrup (1) languages like C++ but not in Haskell where performance is block sorting (1) unpredictable. bloxors (1) boehm (5) BEWARE: People who talk only about scalability and disregard book (3) absolute performance. You can improve the scalability of almost book sales (1) any parallel program by redundantly recomputing the Mandelbrot books (3) set after each line of code for no reason because most of the time boost (1) will then be spent in embarrassingly parallel code. Scalability is boxing (1) necessary but insufficient. You must also look at absolute bubble sort (1) performance. bug (2) bugs (2) burrows wheeler (1) burton smith (1) 8. It took 50 years for normal people to dilute the smug business (1) weenies to the point where you can get a useful answer c# (1) about functional programming on social media. c++ (11) cache (1) I’ve been doing functional programming for over 20 years now. For channel (1) decades there was a social chasm between functional programmers clojure (1) and people who had real problems to solve. Thankfully this problem clos (1) is now starting to dissolve away with functional languages like closures (1) Scala, Clojure and F# being used for real work but for many years clr (1) the predominantly-smug-weenies dominated the functional scene, code base (1) making it hard for people to get real solutions to their real color (1) problems. Part of the reason for this was that, having languished in color laser printer (1) obscurity for so many decades, some communities (most notably commercial (1) Lisp) had highly evolved (but wrong) arguments as to why Lisp was common language runtime (1) good. It took me many years to figure out what was wrong with comparison (1) these arguments. compatibility (1) compiler (4) computer programming (1) concurrency (2) 9. There is a huge amount of misinformation about functional concurrent (6) programming in circulation. concurrent garbage collector (3) concurrent gc (1) If you criticise the performance of hash tables in Haskell (more conservative gc (2) recently here) then you get pure misinformation from the leading consultant (1) lights of the community such as someone advising people to convolution (1) effectively turn off garbage collection. copying collection (1) corruption (1) For years the functional programming community brandished cpu (2) beautifully short implementations of the Sieve of Eratosthenes and darcs (1) Quicksort algorithms. These were even taught to students for data (1) years. Only many years later did it emerge that their solutions did data compression (1) not implement those algorithms. Melissa O’Neill even published a data parallel haskell (3) paper correcting the Sieve of Eratosthenes in Haskell. In particular, database (1) her genuine sieve requires 100x more code than the original debian (1) Haskell. Same for quicksort where Haskell’s elegant two-line sort is determinism (2) over 1,000x slower than Sedgewick’s Quicksort in C because the diffraction (1) Haskell deep copies lists over and over again, completely blowing directx (1) the asymptotic IO complexity of Hoare original algorithm. disadvantages (1) discount (1) See also “Why is Haskell used so little in industry?” for a thorough disruptor (1) debunking of the Haskell in Industry page. don stewart (1) don syme (2)

easy (1) eclipse (1) Posted by Jon Harrop at 12:19 Eric Lippert (1) erik meijer (1) erlang (2) evolutionary (1) examples (2) 8 comments: extensibility (1) f# (30) Panicz said... f# for numerics (1) f# for scientists (1) I think that the point (1) on the lack of "efficient purely f# for technical computing (1) functional unsorded dictionary or set" misses a reference to f# for visualization (1) Clojure's sets and maps and an explanation what is wrong with f# meetup (1) them. f#.net (4) Thanks for this article, by the way. f#.net journal (1) 5 June 2016 at 07:51 fft (1) first-class functions (1) Anthony Lloyd said... fortran (1) fourier (1) For point (3) FP has a completely different way of handling shared state. Shared/global state is represented by a reference free (1) to immutable data structures which is updated atomically. After front end (1) seeing the simplicity and correctness of this I begin to question fsharp (5) that OO in memory database and caching systems are valid funarg problem (1) without a large degree of cross collection locking. These functional (1) complex dependencies lead to concurrency bugs that are very functional programming (9) hard to reason about and solve. funding (1) 5 June 2016 at 09:03 g++ (1) Sara Haberlin said... G1 (1) gainward (1) Yuu blatently lie about point (4). The Haskell solution is much game (1) shorter than the Python one. ganesh sittampalam (1) 5 June 2016 at 12:38 garbage collection (26)

Sara Haberlin said... gc (1) gc pause (1) Also, you attack a strawman when it comes to "purely functional generational garbage collection (1) algorithms". For some algorithms, having mutable state/cells generics (1) leads to a shorter solution than copying data all over the place; ghc (3) fine. But, at least in Haskell, one can wrap that algorithm inside glyn williams (1) the State monad, and it will look identical to the imperative algorithm. google chrome (1) 5 June 2016 at 12:44 google go (1) goroutine (1) Anthony Lloyd said... gpu (1) graphics (3) On point (7) this looks to be more about lower level languages vs higher level. Supercomputers tend to be programmed using graphics card (1) C, C++, Fortran etc without a GC. The code is very optimised guido van rossum (1) low level end of the language spectrum. hard drive (1) hash table (6) FP languages are at a higher level. Its easier and quicker to haskell (30) solve more complex problems with them than low level heap (1) languages. Most of the time CPU cycles are cheaper than heap sort (1) developer cycles. Hence premature optimisation being an anti- herb sutter (2) pattern. hewlett packard (1) I use F# rather than Haskell but I don't recognise your higher-order module (2) observation that parallelism in FP being unpredictable and often hitachi (1) not resulting in a speedup. FP makes parallelisation easier and hlvm (14) safer. It can produce a significant speedup especially for householder reductions (1) embarrassingly parallel problems. This helps tip the cycles hp (2) balance towards FP lanaguages. ide (1) 5 June 2016 at 14:17 idiomatic (1)

Arturo Hernandez said... Immix (1) This comment has been removed by the author. immutable (1) 5 June 2016 at 15:05 imperative (1) industrial haskell group (1) Egg Syntax said... industry (4) intel (3) Could you link to the original Quora question? I' be curious to take a look. Thanks! interview (2) 6 June 2016 at 06:35 io (1) ipad (1) Nicolas said... ironjs (1) java (6) You are very much right about many points. jit (1) At the risk of adding more abstract nonsense, I think there is a job (1) hidden layer of monoidal structure which is absolutely crucial jobs (2) and vastly underappreciated to any program. We are seeing it in joe marshall (1) the ST suggestion from Peaker to have joe pamer (1) jvm (2) forkSTArray :: STVector s a -> Int -> kde (1) (forall s1. STVector s1 a -> ST s1 o1) -> kde 4 (1) (forall s2. STVector s2 a -> ST s2 o2) -> ST s (o1, o2) language (3) laser (1) That is a crucial point which generalizes to other problems, but I latency (4) have not seen it being taken that seriously layout (1) 6 June 2016 at 07:57 leak (2) lecture (1) Post a Comment lexer (1) lexmark (1) Home Older Post limitations (1) lines of code (2) linux (2) Subscribe to: Post Comments (Atom) lisp (3) llvm (4) LMAX (1) loc (1) local optimization (1) london (1) lwt (1) macro (1) mailing list (1) managed code (1) mark compact (2) mark region (5) mark sweep (4) market (2) martin odersky (1) marvell (1) mathematica (8) maximization (1) median (1) memory (3) memory management myths (2) memory safety (1) message passing (1) microsoft (2) milestone (1) MinCut (1) ml (1) mlton (1) module system (1) monad (1) mono (8) monte carlo (1) multicore (1) mutex (1) nacl (1) native code (1) netbook (2) norman ramsey (1) numeric tower (1) numerical (2) numerical methods (3) numerical recipes (1) numerics (1) nvidia (2) o'reilly (2) object oriented programming (3) (31) ocaml for scientists (2) ocaml journal (2) OpenCV (1) optimization (2) pa_monad (1) paper (1) parallel (10) parallel arrays (1) parallel garbage collection (1) parallel programming (1) ParallelTable (1) parser (1) partial specialization (1) pattern (1) pattern matching (1) paul graham (1) pause (1) performance (29) phd (1) plugin (1) polymorphic variants (1) polymorphism (1) popularity (1) printer (1) product (1) products (1) profit (3) profits (1) programming language (1) prompt (1) proper tail recursion (1) public (1) purely functional data structure (3) pythagoras tree (1) python (1) qr decomposition (1) quadcore (1) quicksort (2) raspberry pi (1) ray tracer (4) real-time (2) reddit (1) reference counting (9) reference type (1) regular expression (1) reified generics (2) release (1) reliability (1) representation (1) research (1) review (4) rewrite (1) rich hickey (1) richard jones (1) rule (1) running cost (1) sadek drobi (1) sal mangano (1) sales (4) scala (10) scheme (1) scientific computing (1) semi-space (1) shadow stack (1) share (2) shared_ptr (1) signal (1) simon marlow (1) simple (1) size (1) smart pointers (1) sml (2) software (1) source code (1) special offer (2) sse (1) stack overflow (1) (1) stencil (1) stop-the-world (1) structural (1) sun (1) symbolic (1) tail calls (3) task parallelism (1) tco (1) technical computing (1) template haskell (1) term rewriting (1) Texas Multicore Technologies (1) thesis (1) thread safe (1) throughput (1) time-frequency analysis (1) tools (1) tracing garbage collection (1) trading (1) treadmill (1) trend (2) trends (1) tuples (1) tutorial (2) type class (1) value (1) value types (2) variant type (1) verbosity (2) video (2) virginity (1) virtual machine (1) vista (1) visual studio integration (1) visualization (2) wavelet (1) weak dictionary (1) weak references (1) western digital (1) windows (1) write barrier (1)

About Me

Jon Harrop

Specialist in the use of functional programming for technical computing in industry and academia. View my complete profile

Total Pageviews 469,928