anonymous closures with Proc,new, lambda and ->

S

Steve Klabnik

[Note: parts of this message were removed to make it a legal post.]

Naw, monads are actually really, really easy. They're just poorly
explained... one day, they just clicked for me, and I can't believe it took
me all this time to learn them.
 
S

Stu

My interest in learning functional programming( or at least the
foundation of) is because I haven't done it before( though I flirted
with scheme a couple years ago). I don't really know what monads are I
was just compiling a list of "things I should look into" for future
reference to take the autodidactic approach to learning functional
paradigms.

When I first to the plunge to learn object oriented paradigm from a
procedural background I know I made it harder than it is. The first
thing I did to tackle the learning curve was to break down the four
concept layers encapsulation, inheritance, polymorphism and
abstraction. It wasn't until I began creating composite objects,
sending messages and creating observer objects until it finally hit me
and all seemed so simple that I didn't understand why it was so hard
in the first place.

As a side note the Ruby Language shows just how well an object
oriented program is. Simply the organisation behind every object in
it's own inheritance hierarchy all the way down to BasicObject,
polymorphic design of variants like lambda and Proc.new. Even the
redefinition of operators to deal with primitive and abstract data
types in their own domain( i.e. 3 * 3, [42,3] - [3,45,54], "lamda " *
3)... This is inspirational for modelling my own objects with this
type of object framework if I may be so =C0 Propos.

My background consists of posix shell scripting( ash, awk) and some c.
My interest in ruby has been to add a general purpose programming
language to my toolbox. After I get to a proficiency apex with ruby I
have in the learning queue to go back and refresh my c knowledge and
take the time to truly grok the fundamental data structures and
algorithms. Once that goal is hit I had planned to move to c++. C++0x
will be incorporating lambda and closures. I imagine c++ will be a
life long journey as it's a multi-paradigm programming language as
well. (is it 4 or 5 languages in one now?)

As Robert pointed out Ruby may not be the best language to learn
functional programming concepts with. This speaks volumes to me as I
am a huge proponent to the attitude to use the right tool for the
right job. If I am not mistaken most of these languages are dialects
of Lisp( correct me if I am wrong). I am not in a position to learn to
earn nor am I a mathematician. My interest is to simply better myself
as a programmer.

Those of you who have used Haskell monads does one really need to have
invented string theory to understand it or is it like how I explained
the object oriented learning curve where one might over-think it's
simplicity therefor overcomplicating their comprehension of the
paradigm?

Also is there a canonical or pedagogical tutorial for me to start
with? Hello, World! =3D)

Which language would be a decent new users language which would fit
well into my unix toolkit above as well as threading the knowledge
back into ruby's hybrid programming? (scheme, haskell, clojure common
lisp)

Thanks in advance

~Stu
 
B

Brian Candler

Stu wrote in post #994213:
Which language would be a decent new users language which would fit
well into my unix toolkit above as well as threading the knowledge
back into ruby's hybrid programming?

If you are coming to functional programming from an imperative
background, I would recommend Erlang as a sound starting point. It's a
highly practical language for real-world applications, albeit with a
frustrating syntax.

In Erlang, functions can and do have side effects, in particular the
sending of messages between processes. However variables can be bound
only once, and data structures are immutable. There is no "A = A + 1"
:)

So each individual process is functional, and you start getting your
head around functional algorithms "in the small", such as using
recursion for looping and traversing data structures. But you don't have
to worry about building your entire application in a purely functional
form.

The immutability of data means concurrency is easy (no mutexes!) and you
have zero-copy passing of data structures, at least between processes on
the same node.
 
R

Robert Klemme

Also is there a canonical or pedagogical tutorial for me to start
with? Hello, World! =)

Well, the typical program which prints "Hello World!" is difficult for
_purely_ functional languages since IO is a side effect. Of course, a
language which could not interface with the outside world would be
deemed to be purely academical. Maybe in the functional world the
equivalent example should be "2 * 4"? :)

Cheers

robert
 
R

Robert Klemme

My interest in learning functional programming( or at least the
foundation of) is because I haven't done it before( though I flirted
with scheme a couple years ago). I don't really know what monads are I
was just compiling a list of "things I should look into" for future
reference to take the autodidactic approach to learning functional
paradigms.

I just came across this report how others teach FP:
http://existentialtype.wordpress.com/2011/04/17/some-advice-on-teaching-fp/

Cheers

robert
 
7

7stud --

Stu wrote in post #994213:
As Robert pointed out Ruby may not be the best language to learn
functional programming concepts with.

I would agree with that. Functional programming is much different than
creating a ruby closure.

Also is there a canonical or pedagogical tutorial for me to start
with? Hello, World! =)

Learn you a Haskell for great Good!

http://learnyouahaskell.com/

Just start the tutorial, and see what you can see.
 
S

Steve Klabnik

[Note: parts of this message were removed to make it a legal post.]

+1 for learn you a haskell.

Ruby does have functional elements, but you won't truly learn FP, because
Ruby is all about structuring programs in an OO fashion, and solving small
problems in FPish ways when it makes sense. If that makes sense. Using a
'real' FP language will make you structure your problems in a functional
way...

Erlang would be okay too, but Haskell is better. Scheme is also solid. But
Haskell is uber-strict, and so you'll end up really learning FP well.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top