4 ms·
That's functional programming for you. It's definitely less efficient, but there are other major advantages. For one thing, given the propagation of immutable d
by rybosome 13y ago
That's functional programming for you. It's definitely less efficient, but there are other major advantages. For one thing, given the propagation of immutable data, things can be parallelized effortlessly - look at 'pmap' in Clojure for example. Once you're familiar with the style, it's significantly more concise and readable.
That being said, a systems programming language may not be the right place for FP concepts.
- saryant 13y agoScala gets around this with "views": store the higher-order functions until the collection actually needs to be used and then apply them all at once, without any intermediate data structure. http://docs.scala-lang.org/overviews/collections/views.html http://docs.scala-lang.org/overviews/collections/views.html
- coolsunglasses 13y ago>That's functional programming for you. Uhm, what? No it's not. Haskell has stream fusion, thereby generating assembler that looks a lot like the optimal imperative version.
- rybosome 13y agoVery cool - I was not aware of this feature. Fwiw, I'm actually something of an FP zealot; I failed to make a stronger case in my comment because I'm tired of arguing, and I'm concerned that I'm being obnoxious.
- burntsushi 13y agoThis is kind of misleading. Stream fusion isn't baked into Haskell; you need to use a library. [1,2] [1] - https://ghc.haskell.org/trac/ghc/ticket/915 [2] - http://hackage.haskell.org/package/stream-fusion
- danieldk 13y agoBut, many of the commonly used libraries already use stream fusion, e.g. vector and text.
- coolsunglasses 13y agohttp://hackage.haskell.org/package/text-0.1/docs/Data-Text-Fusion.html http://hackage.haskell.org/package/text-0.1/docs/Data-Text-F... http://hackage.haskell.org/package/vector-0.9.1/docs/Data-Vector-Fusion-Stream.html http://hackage.haskell.org/package/vector-0.9.1/docs/Data-Ve... Except it's bloody everywhere in the libraries you use and you can design your own libraries around it. A language powerful enough that things like this can be done in libraries instead of in the compiler is a good thing.
- Dewie 13y ago> That being said, a systems programming language may not be the right place for FP concepts. It's good enough for Rust.
- pcwalton 13y agoNote that the Rust compiler doesn't do any stream fusion; rather the functional idioms are designed around iterators, which provide a functional interface that relatively easily and predictably compiles down to code that's as efficient as the corresponding for loop.
- rybosome 13y agoI wondered about that - Rust looks like the one systems programming language I would actually enjoy using, but I don't know enough about it to have an informed opinion.
- krakensden 13y ago> things can be parallelized effortlessly If you're not using a language with Clojure's nifty datastructures, "effortlessly" probably isn't much better than OpenMP.
- atilaneves 13y agoD is a systems programming language with FP concepts and they work quite well. Also, it has generics / templates / parametric polymorphism that are more powerful and easier to use than C++.
- chongli 13y agoRight, but it still employs a machine model of computation. This is fundamentally different from FP's language model. https://existentialtype.wordpress.com/2011/03/16/languages-and-machines/ https://existentialtype.wordpress.com/2011/03/16/languages-a...