LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-25-2009, 12:53 PM   #1
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 85
Learning functional programming


I am rather fascinated by what little I know of functional programming, and would like to learn more, when I have time. Been doing a bit of shopping around, and not sure which direction to head in.

I currently am fairly competent in PHP, Java and Perl. My aim with FP would be to learn a new way of approaching or thinking about programming.
  • The Haskell books do not tend to get great review on Amazon, but I did find the chapter in Beautiful Code enticing
  • Programming Erlang by Joe Armstrong does get a good review, but only one
  • I understand Lisp is the "grand-daddy" of them all, and Practical Common Lisp does get good reviews
  • Or I could stick with a language I already know something about and get Higher Order Perl

So any advice and book recommendations?

Thanks,
Rob

Last edited by Robhogg; 03-25-2009 at 12:55 PM. Reason: Politeness
 
Old 03-25-2009, 01:10 PM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Lisp, Lisp, Lisp!!!

It's a blast.

My biggest selling point on Lisp is its syntax; some people (like myself) love it, other people hate it (saying things like "too many parentheses").

Practical Common Lisp is a swell book - it got me started on the language - but I highly recommend, also, getting a copy of ANSI Common Lisp (it makes for a killer reference book for standard functions), and see if you can get a copy of Common Lisp: A Gentle Introduction to Symbolic Computation (it provides a wonderful, thorough, easy-to-follow introduction on how Lisp works - thus, explaining its syntax).

Last edited by indienick; 03-25-2009 at 01:13 PM.
 
Old 03-25-2009, 01:18 PM   #3
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Original Poster
Rep: Reputation: 85
Quote:
Originally Posted by indienick View Post
Lisp, Lisp, Lisp!!!
You sound like a friend of mine when Ruby is mentioned ;-).

So if I wanted only one book to be going on with (at the moment, anyway), is Practical Common Lisp the one to start with?
 
Old 03-25-2009, 01:20 PM   #4
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
I would most certainly say so!

Also, for what it's worth, Common Lisp: A Gentle Introduction to Symbolic Computation is available for free as a PDF - just take it to a Kinkos (or "FedEx Express" as they're called, now) and get them to print it, and bind it, for you.
 
Old 03-25-2009, 01:29 PM   #5
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
But, I thought functional programming was superseded by OOP ... right ?

If you like functional programming, go for C, it'll be useful and functional programming (but may be a bit difficult, but if you know other languages already it shouldn't be too hard)
 
Old 03-25-2009, 01:37 PM   #6
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 41
Haskell is a good language but I find that there are many things that I do not yet understand about it. Real World Haskell is supposed to be good but I haven't read it yet. One of my biggest problems with Haskell though is that the main implementation that everybody uses doesn't run on many platforms. Also it's about the opposite of Lispy languages in that it has a lot of syntax, people love to make random operators and as a result Haskell source can be very dense and hard to read.

Common Lisp is a great language with many good implementations. It's a bit messy for my tastes in some respects (e.g. functions that take a thousand optional parameters) but it's designed to be complete, not necessarily simple. Paul Graham's books ANSI Common Lisp and On Lisp are great.

Scheme is another great one, and IMHO the best for a beginner, though that does not by any means imply that it's limited. I've been reading R. Kent Dybvig's The Scheme Programming Language which is excellent. By chapter three he covers how everything in Scheme can be implemented with a few core forms. It really changes the way you think about programming to realize that looping and variable binding can be done with lambda forms and function application. You should also read the Lambda the Ultimate papers as well if you go this route. (See also: http://www.ccs.neu.edu/home/dorai/t-...-y-scheme.html)

There are also strict (i.e. non-lazy) strongly statically typed functional languages like SML and OCaml which are both worth learning as they give you a slightly different angle on things. Erlang is functional but adds some neat elements from Prolog to the mix.

Given infinite time and energy, I would learn Scheme completely (that won't take long). Then touch Common Lisp to understand its differences with Scheme. Next learn Standard ML and pick up Haskell to the point that you understand its additions to the type system and use of laziness. Hit Erlang if you want; pay attention to its concurrency support, error-handling systems, and pattern resolution. Then you'll be ready to use functional features in day-to-day languages (Higher-Order Perl is a very good book) and understand when / why they're more limited than comparable features in "real" functional languages.

Last edited by taylor_venable; 03-25-2009 at 01:45 PM.
 
Old 03-25-2009, 01:39 PM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by H_TeXMeX_H View Post
But, I thought functional programming was superseded by OOP ... right ?

If you like functional programming, go for C, it'll be useful and functional programming (but may be a bit difficult, but if you know other languages already it shouldn't be too hard)
Wrong. OOP, AFAIK, is easily derived from functional.

Regarding "C" - GNU dialect at least allows function definitions inside functions - very typical for functional programming.

...

"Perl is damn good functional language" (or something like that) - from OCaml tutorial.

Try OCaml and Haskell - Perl 6 was heavily influenced by Haskell.

The above two are strictly typed - unlike Perl 5.
 
Old 03-25-2009, 02:16 PM   #8
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51
Blog Entries: 1

Rep: Reputation: 16
I would recommend Haskell the craft of functional programming.I am a first year computer science student and I have tried a few other functional programming languages before.The beauty of Haskell is that it introduces functional programming using it's own built data types and functions and when you get an understanding of the paradigm then the fun stuff starts.You get to "go under the bonnet" of these data types and functions to see how they have been written and how easily you see how they were created when you get to understand how the work.The approach is gentle and you wont get lost if you follow the book page by page.
 
Old 03-25-2009, 03:49 PM   #9
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Original Poster
Rep: Reputation: 85
Quote:
Originally Posted by H_TeXMeX_H View Post
If you like functional programming, go for C...
C is generally considered to be an imperative programming language. Functional programming is something a lot weirder. Although I daresay, as Sergei suggests, you could write functional stuff in C. One of the other fascinating essays in Beautiful Code is on theLinux kernel drivers model - halfway through reading it I thought "hey - they're doing object oriented programming. In C!"

The difference is (as I understand it), in imperative languages you write a series of instructions to get from state A to state B, whereas in functional language you write a function (akin to a mathematical function) that describes the relationship between state A and state B, and let it get on with it.

@Taylor_Venable:
Scheme is a language that I've only barely heard of (although I could say the same for Erlang). Sounds interesting, though. Thanks - I'll definitely check out the link.

What attracts me most to Lisp is Greenspun's Tenth Rule of Programming
Quote:
Any sufficiently complicated C or Fortran program contains an ad hoc informally-specified bug-ridden slow implementation of half of Common Lisp.


@3vra:
I'd been a bit put off of that book by the very mixed reviews on Amazon, but I will give it another look.

Thanks,
Rob

Last edited by Robhogg; 03-25-2009 at 03:53 PM.
 
Old 03-25-2009, 04:15 PM   #10
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by 3vra View Post
I would recommend Haskell the craft of functional programming.I am a first year computer science student and I have tried a few other functional programming languages before.The beauty of Haskell is that it introduces functional programming using it's own built data types and functions and when you get an understanding of the paradigm then the fun stuff starts.You get to "go under the bonnet" of these data types and functions to see how they have been written and how easily you see how they were created when you get to understand how the work.The approach is gentle and you wont get lost if you follow the book page by page.
Haskell looks really clean and elegant, however, it's a pure functional language. And sometimes this makes life difficult.

Opposed to Haskell OCaml has two clearly defined parts: functional and imperative. This is good IMO - when pure functional approach gets in the way of solving the problem one can switch to imperative. An example they give is GUI stuff.

It appears that Haskell and OCaml communities are friendly towards each other.

I think OCaml is more practical; it has interesting "dialects" - see JOcaml, for example. In this case dialect is a good thing.
 
Old 03-25-2009, 05:04 PM   #11
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 41
Robhogg: In the beginning there was LISP; then came Scheme and Common Lisp. Both Scheme and CL are descendants of the original ideas in LISP, they've just gone down different paths of evolution. In my mind, saying "LISP" or "Lisp" is more ideological, and for implementation you've then got the choice of Scheme or Common Lisp. I recommend Scheme first because those original ideas are more simplified, generalised, and laid bare in Scheme than CL. Learning CL after Scheme can show you new or different ways in which those core ideas were extended to fit a different kind of goal in the language.
 
Old 03-25-2009, 09:30 PM   #12
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
I would just like to tack on to the end of taylor_venable's post, that in Scheme being a much cleaner (argumentatively "purer") Lisp dialect, from what I have seen it places a heavier emphasis on the use of Lambda functions in places where Common Lisp would already have a standardized function.
 
Old 03-25-2009, 10:53 PM   #13
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 59
If you're familiar with Perl and curious about functional style programming and higher order programming (passing functions as values to functions), then I cannot recommend Higher Order Perl strongly enough. It's available online free, and well worth buying if you prefer dead tree books. (I still prefer paper for books I really carry about.)

I'm also surprised that nobody's mentioned Structure and Interpretation of Computer Programs which is an all-around classic.
 
Old 03-25-2009, 11:18 PM   #14
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by H_TeXMeX_H View Post
But, I thought functional programming was superseded by OOP ... right ?

If you like functional programming, go for C, it'll be useful and functional programming (but may be a bit difficult, but if you know other languages already it shouldn't be too hard)
C is procedural with minimal OOness. Functional programming is also OO in one way or another.
Kevin Barry

edit:
Unless you mean "you can write programs that function in C," which I wouldn't argue with...
 
Old 03-26-2009, 11:48 AM   #15
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51
Blog Entries: 1

Rep: Reputation: 16
@Robhogg
I think you need to be a bit more specific regarding your intentions.Do you want to go deep into functional programming or do you want to or you just want to be knowledgeable.

All the languages mentioned are really good languages and the all can help you to understand functional programming but there are programming languages that are designated to strictly functional programming.Therefore depending on what you want we can make better recommmendations.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Learning Programming yeehi Suse/Novell 10 11-25-2007 09:33 AM
functional programming in C++ synss Programming 2 08-03-2007 02:33 AM
Functional Programming - Discussion taylor_venable Programming 6 07-30-2006 11:20 PM
LXer: Everything Your Professor Failed to Tell You About Functional Programming LXer Syndicated Linux News 0 01-31-2006 10:31 PM
learning programming nin881 Programming 13 10-19-2005 01:17 AM


All times are GMT -5. The time now is 09:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration