Can one use Python to learn and even apply Functional Programming?

Discussion in 'Python' started by Sam, Feb 16, 2014.

  1. Sam

    Sam Guest

    I would like to learn and try out functional programming (FP). I love Python and would like to use it to try FP. Some have advised me to use Haskell instead because Python is not a good language for FP. I am sort of confused at the moment. Is Python a dysfunctional programming language to apply FP? Can the more experienced Python users advise?
    Sam, Feb 16, 2014
    1. Advertisements

  2. Everything about FP that can be done in, say, Scheme, can be done in
    Python, with the exception of tail recursion (but that isn't important
    for "real" FP). But Scheme is old, and people keep thinking of new
    things and more interesting variations on the lambda calculus.

    Haskell is kind of the core of modern functional programming, and
    involves heavy use of concepts that do not exist or are visibly alien
    in Python. If you want to learn FP properly, you should learn Haskell.
    Otherwise you will likely be confused when you overhear functional
    programmers talking, whether it's about Hindley-Milner or sum types or
    eta conversion.

    -- Devin
    Devin Jeanpierre, Feb 16, 2014
    1. Advertisements

  3. ETA conversion? I know what that is. That's when a programmer says
    something'll take six months, and the marketing guys start selling it
    for delivery in three.

    *dives for cover*

    Chris Angelico, Feb 16, 2014
  4. Sam

    Pat Johnson Guest

    This made me grin. ;)
    Pat Johnson, Feb 16, 2014
  5. Sam

    Terry Reedy Guest

    You can do tail recursion in Python, but it will not be noticed and
    optimized in the way it is is some functional languages.
    In some ways, Haskell is more different from Python than Scheme is, so
    it may stretch your brain more.
    Terry Reedy, Feb 16, 2014
  6. What did, using google groups? :)
    Mark Lawrence, Feb 16, 2014
  7. "Well! I've often seen context without a grin," thought Alice; "but a grin
    without context! It's the most curious thing I ever saw in my life!"

    Chris Angelico, Feb 16, 2014
  8. Sam

    Rustom Mody Guest

    For many years I taught programming in which a pure functional language wasthe
    'mother-tongue' and was followed by a multi-paradigm language.
    In the 90s the pair was Miranda + Scheme; after 2001 it was
    a haskell (wee-subset) + python.

    Two of the bedrock items for a FP education is
    1. Getting Hindley-Milner*
    2. Lambda Calculus

    1 python does not have at all and 2 is ok but not great.

    Once Hindley-Milner is in your bones -- yeah its radioactive and harmless --
    you can happily think in pseudo-Haskell and code in(to) python (or C++ or

    The syllabus I made and used (well kindof :) )

    I must say I am not personally too happy with haskell's direction today -- its
    'progress' looks quite like how C++ 'progresses' C.
    [Yeah this does not amount to a very helpful direction :-( ]

    In more abstract, here is a blog-post of mine
    which lists out (in very brief) concepts/features that originated from
    FP and would benefit programmers irrespective of language/paradigm/technology
    they are currently into.
    Rustom Mody, Feb 16, 2014
  9. Sam

    Ryan Guest

    Python*can* do functional programming, but, for learning, Haskell will work better.
    Ryan, Feb 16, 2014
  10. Sam

    Neil Cerutti Guest

    I recommend Scheme to learn functional programming style.

    There's a short scheme tutorial that was entered in the
    Interactive Fiction competition in 1998 or so. You can play it
    online here, and try out functional programming on a scheme
    interepreter implemented in Inform and running on a Z-machine
    interpreter written in javascript. It was *my* first introduction
    to functional programming.

    I purchased and really enjoyed Simply Scheme as a followup to
    that mind-bending experience.

    I wouldn't recommend trying to learn anything at the same time as
    learning Haskell. ;)
    Neil Cerutti, Feb 18, 2014
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.