[Haskell-beginners] Doubts about functional programming paradigm
Thomas Jakway
tjakway at nyu.edu
Fri Dec 11 18:32:55 UTC 2015
Building on that, I think coming to Haskell with a very specific goal in mind (like swap Haskell for Java in my map reduce problem) kind of misses the point. Haskell may or may not be faster/better suited to map reduce vs Java, but the real reason to use/learn Haskell is elegance and correctness. The lack of side effects and referential transparency means you're far more likely to prevent bugs. And there's a pretty substantial learning curve coming from imperative languages so if you need to speed up map reduce on a deadline you will be more productive in the imperative language of your choice (for now).
Dont take this as discouragement, I think Haskell (and FP in general) is very well suited to that kind of problem. I'm a beginner in Haskell and it's already had a huge impact on how I think about all the code I write, not just the occasional toy Haskell project.
On Dec 11, 2015 1:08 PM, MJ Williams <matthewjwilliams101 at gmail.com> wrote:
>
> A pure functional language enables you to reason about your code,
> something you can't easily achieve with your average C or Java. And by
> `reason' I am referring to mathematical proof. Haskell makes it very
> simple, actually. Why should you want to reason about your code?
> Think the hassle you could avoid if you knew what your code really
> meant and did when executed.
>
> The absence of side effects is part of another concept in FP, namely,
> `referential transparency'. If your function `f' maps a value `x' to
> a value `y' then `f x' will always equal `y' and no more. In other
> words, your function `f' won't change anything e.g. assign to
> variables, or other state changes as well as mapping `x' to `y', and
> that's an absolute certainty, in theory, at any rate.
>
> That's a very crude overview of at least part of what functional
> programming is about. I'm hoping it'll encourage others on this list
> with far more in-depth knowledge of the subject matter to come in and
> fill in the gaps and iron out the ambiguities.
>
> Matthew
>
>
> On 11/12/2015, Daniel Bergey <bergey at alum.mit.edu> wrote:
> > On 2015-12-11 at 10:07, Abhishek Kumar <abhishekkmr18 at gmail.com> wrote:
> >> I am a beginner in haskell.I have heard a lot about haskell being great
> >> for
> >> parallel programming and concurrency but couldn't understand why?Aren't
> >> iterative algorithms like MapReduce more suitable to run parallely?Also
> >> how
> >> immutable data structures add to speed?I'm having trouble understanding
> >> very philosophy of functional programming, how do we gain by writing
> >> everything as functions and pure code(without side effects)?
> >> Any links or references will be a great help.
> >
> > Functional languages make it easy to decompose problems in the way that
> > MapReduce frameworks require. A few examples (fold is another name for
> > reduce):
> >
> > sum :: [Double] -> Double
> > sum xs = foldr (+) 0 xs
> >
> > sumSquares :: [Double] -> Double
> > sumSquares xs = foldr (+) 0 (map (**2) xs)
> >
> > -- foldMap combines the map & fold steps
> > -- The Monoid instance for String specifies how to combine 2 Strings
> > -- Unlike numbers, there's only one consistent option
> > unlines :: [Text] -> Text
> > unlines xs = foldMap (`snoc` '\n') xs
> >
> > We'd need a few changes[1] to make this parallel and distribute across many
> > computers, but expressing the part that changes for each new MapReduce
> > task should stay easy.
> >
> > Immutable data by default helps with concurrency. Speed may or may not be
> > the goal. We want to be able to distribute tasks (eg, function calls)
> > across processor cores, and run them in different order, without
> > introducing race conditions.
> >
> > Simon Marlow's book is great at explaining parallel & concurrent
> > concepts, and the particular tools for applying them in Haskell:
> > http://chimera.labs.oreilly.com/books/1230000000929
> >
> > bergey
> >
> > Footnotes:
> > [1] OK, many changes.
> >
> > _______________________________________________
> > Beginners mailing list
> > Beginners at haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
More information about the Beginners
mailing list