Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66506 > unrolled thread

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

Started bySam <lightaiyee@gmail.com>
First post2014-02-15 20:45 -0800
Last post2014-02-18 16:39 +0000
Articles 12 — 10 participants

Back to article view | Back to comp.lang.python


Contents

  Can one use Python to learn and even apply Functional Programming? Sam <lightaiyee@gmail.com> - 2014-02-15 20:45 -0800
    Re: Can one use Python to learn and even apply Functional Programming? Chris Angelico <rosuav@gmail.com> - 2014-02-16 16:34 +1100
    Re: Can one use Python to learn and even apply Functional Programming? Ben Finney <ben+python@benfinney.id.au> - 2014-02-16 16:42 +1100
    Re: Can one use Python to learn and even apply Functional Programming? Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-02-15 22:38 -0800
    Re: Can one use Python to learn and even apply Functional Programming? Chris Angelico <rosuav@gmail.com> - 2014-02-16 18:04 +1100
      Re: Can one use Python to learn and even apply Functional Programming? Pat Johnson <p.johnson125@gmail.com> - 2014-02-16 00:00 -0800
        Re: Can one use Python to learn and even apply Functional Programming? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-16 13:20 +0000
        Re: Can one use Python to learn and even apply Functional Programming? Chris Angelico <rosuav@gmail.com> - 2014-02-17 00:28 +1100
    Re: Can one use Python to learn and even apply Functional Programming? Terry Reedy <tjreedy@udel.edu> - 2014-02-16 03:40 -0500
    Re: Can one use Python to learn and even apply Functional Programming? Rustom Mody <rustompmody@gmail.com> - 2014-02-16 05:52 -0800
    Re: Can one use Python to learn and even apply Functional Programming? Ryan <rymg19@gmail.com> - 2014-02-16 09:11 -0600
    Re: Can one use Python to learn and even apply Functional Programming? Neil Cerutti <neilc@norwich.edu> - 2014-02-18 16:39 +0000

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

FromSam <lightaiyee@gmail.com>
Date2014-02-15 20:45 -0800
SubjectCan one use Python to learn and even apply Functional Programming?
Message-ID<3fd33e3a-7774-4988-b725-4fed5472ac94@googlegroups.com>
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?

[toc] | [next] | [standalone]


#66508

FromChris Angelico <rosuav@gmail.com>
Date2014-02-16 16:34 +1100
Message-ID<mailman.7037.1392528858.18130.python-list@python.org>
In reply to#66506
On Sun, Feb 16, 2014 at 3:45 PM, Sam <lightaiyee@gmail.com> wrote:
> 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?
>

Functional programming is a particular style. Python supports some of
that style, but it certainly doesn't enforce it; if you want to learn
how to work within a functional style, you'd do better with a language
that won't let you do anything else.

Python does have a number of extremely handy notations, borrowed from
more functional languages. But it's not a functional language,
primarily. It's what you might call "multi-paradigm" [1], but
primarily imperative and object-oriented (everything's an object).

ChrisA

[1] My buzzword limiter is starting to smoke

[toc] | [prev] | [next] | [standalone]


#66509

FromBen Finney <ben+python@benfinney.id.au>
Date2014-02-16 16:42 +1100
Message-ID<mailman.7038.1392529369.18130.python-list@python.org>
In reply to#66506
Sam <lightaiyee@gmail.com> writes:

> Some have advised me to use Haskell instead because Python is not a
> good language for FP.

There are some features of functional programming which are not a good
fit with Python. By attempting to learn functional programming in
Python, you will necessarily compromise your Python code *and* your
understanding of functional programming.

> I am sort of confused at the moment. Is Python a dysfunctional
> programming language to apply FP? Can the more experienced Python
> users advise?

I think if you want to learn functional programming you should have a
good reason for doing so, and you should learn something like Common
Lisp or Scheme or another purely-functional language.

You will definitely learn a lot about programming that you didn't know
before, and be able to think about problems with an expanded mental
toolkit.

Similarly, I encourage anyone working with databases to learn correct
relational database techniques — even though SQL is a deeply-flawed and
rather incomplete tool for working with relational databases,
nevertheless learning relational theory gives one an expanded mental
toolkit for thinking about database design and access when working in
SQL.

Much of the functional programming toolkit will apply to your Python
programming, but you will need to be aware of what tru functional
programming is, and then bring that toolkit back to Python.

-- 
 \         “If nature has made any one thing less susceptible than all |
  `\    others of exclusive property, it is the action of the thinking |
_o__)                          power called an idea” —Thomas Jefferson |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#66510

FromDevin Jeanpierre <jeanpierreda@gmail.com>
Date2014-02-15 22:38 -0800
Message-ID<mailman.7039.1392532785.18130.python-list@python.org>
In reply to#66506
On Sat, Feb 15, 2014 at 8:45 PM, Sam <lightaiyee@gmail.com> wrote:
> 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?

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

[toc] | [prev] | [next] | [standalone]


#66511

FromChris Angelico <rosuav@gmail.com>
Date2014-02-16 18:04 +1100
Message-ID<mailman.7040.1392534293.18130.python-list@python.org>
In reply to#66506
On Sun, Feb 16, 2014 at 5:38 PM, Devin Jeanpierre
<jeanpierreda@gmail.com> wrote:
> Otherwise you will likely be confused when you overhear functional
> programmers talking, whether it's about Hindley-Milner or sum types or
> eta conversion.

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*

ChrisA

[toc] | [prev] | [next] | [standalone]


#66512

FromPat Johnson <p.johnson125@gmail.com>
Date2014-02-16 00:00 -0800
Message-ID<c5568dfb-93a5-4c88-bc0e-464e47c44a61@googlegroups.com>
In reply to#66511
This made me grin. ;)

[toc] | [prev] | [next] | [standalone]


#66531

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-02-16 13:20 +0000
Message-ID<mailman.7052.1392556861.18130.python-list@python.org>
In reply to#66512
On 16/02/2014 08:00, Pat Johnson wrote:
> This made me grin. ;)
>

What did, using google groups? :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [prev] | [next] | [standalone]


#66534

FromChris Angelico <rosuav@gmail.com>
Date2014-02-17 00:28 +1100
Message-ID<mailman.7055.1392557296.18130.python-list@python.org>
In reply to#66512
On Mon, Feb 17, 2014 at 12:20 AM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
> On 16/02/2014 08:00, Pat Johnson wrote:
>>
>> This made me grin. ;)
>>
>
> What did, using google groups? :)

"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!"

ChrisA

[toc] | [prev] | [next] | [standalone]


#66520

FromTerry Reedy <tjreedy@udel.edu>
Date2014-02-16 03:40 -0500
Message-ID<mailman.7044.1392540068.18130.python-list@python.org>
In reply to#66506
On 2/16/2014 1:38 AM, Devin Jeanpierre wrote:
> On Sat, Feb 15, 2014 at 8:45 PM, Sam <lightaiyee@gmail.com> wrote:
>> 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?
>
> 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

You can do tail recursion in Python, but it will not be noticed and 
optimized in the way it is is some functional languages.

> 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.

In some ways, Haskell is more different from Python than Scheme is, so 
it may stretch your brain more.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#66535

FromRustom Mody <rustompmody@gmail.com>
Date2014-02-16 05:52 -0800
Message-ID<7cff3812-2bc6-410e-9e6a-f849d39f801d@googlegroups.com>
In reply to#66506
On Sunday, February 16, 2014 10:15:58 AM UTC+5:30, Sam wrote:
> 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?

For many years I taught programming in which a pure functional language was the
'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 
whatever)

The syllabus I made and used (well kindof :-) )
http://www.the-magus.in/Publications/ip.pdf

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
http://blog.languager.org/2012/10/functional-programming-lost-booty.html
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.

[toc] | [prev] | [next] | [standalone]


#66543

FromRyan <rymg19@gmail.com>
Date2014-02-16 09:11 -0600
Message-ID<mailman.7060.1392563496.18130.python-list@python.org>
In reply to#66506

[Multipart message — attachments visible in raw view] — view raw

Python*can* do functional programming, but, for learning, Haskell will work better.

Sam <lightaiyee@gmail.com> wrote:
>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?
>-- 
>https://mail.python.org/mailman/listinfo/python-list

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

[toc] | [prev] | [next] | [standalone]


#66636

FromNeil Cerutti <neilc@norwich.edu>
Date2014-02-18 16:39 +0000
Message-ID<mailman.7118.1392741630.18130.python-list@python.org>
In reply to#66506
On 2014-02-16, Sam <lightaiyee@gmail.com> wrote:
> 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?

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.

http://www.eblong.com/zarf/if.html#lists

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

http://www.eecs.berkeley.edu/~bh/ss-toc2.html

I wouldn't recommend trying to learn anything at the same time as
learning Haskell. ;)

-- 
Neil Cerutti

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web