What I would like to have is some sort of lexicon to at least help
explain the terminology in a way that doesn't require three years of
academic exposure to functional programming to read. Is there such a
reference? Or should I just ignore threads like "Why do functions in
the state monad only accept one value?" and be happy that at least
somebody cares about this stuff, so that I don't have to?
Ben
http://news.ycombinator.com/item?id=1033503
Personally, I'd recommend Programming Clojure as a good place to
start.
Sean
On Mar 17, 8:28 am, Ben Armstrong <synerg...@gmail.com> wrote:
> I am new to clojure and functional programming, but not to programming
> in general, having been in the profession for a quarter of a century.
> I'm trying to stretch myself a bit by learning clojure, but some of the
> threads here go beyond mere stretching to verge on head-exploding. In
> my offline reading of this list this morning, I tried using the tools
> available to me at the time (dict client and a few dictionaries like
> foldoc) to make sense of words like: http://foldoc.org/monad. I
What I would like to have is some sort of lexicon to at least help explain the terminology in a way that doesn't require three years of academic exposure to functional programming to read. Is there such a reference? Or should I just ignore threads like "Why do functions in the state monad only accept one value?" and be happy that at least somebody cares about this stuff, so that I don't have to?
Ben
I'm considering using the continuation monad to implement a parser
that can pick up where it left off. However, I agree that they're very
rarely used in Clojure.
- James
> But seriously, in my personal opinion Monads are relatively useless
> in the context of Clojure.
I'd say that in any impure functional language, monads are useful in
the context of specific applications or algorithmic approaches. When
working with continuations, or when writing complex parsers, monads
are useful. It's just Haskell that has a language-specific relation to
monads, because it needs them for fundamental tasks such as I/O.
Konrad.
Yes, ignore those for now. Write an entire program in Clojure before
you read anything about monads. They aren't required. When I first
dipped my toes in the functional waters I learned a lot from "Casting
SPELs in LISP"[1]. It's based around Common Lisp, but it should be
easily translatable to Clojure.
Thanks. Yes, I have already started with "Programming Clojure". It is
because it doesn't go deeply into FP ('monad' is mentioned once, in an
aside, and is unexplained in that reference) that I was looking for
other references. I'll have a look at some of the others on this page.
Ben
Ben,
You can do a LOT with just a basic level of Clojure. I'm writing a
database
loader to help support an iPhone app I'm writing, and got done in just
a few
hours whilst only scratching the surface of what's available. No
paralleism,
no monads, no macros, no refs.
My opinion, and it may only be valid for me, is learning a language
works
best when you have a definite task, and you can build code, then
better
code, then even better code in the language you're trying to learn.
I have a couple of the books, but as yet, the best method for
learning
seems to be google and example code.
Tim Bray has a Clojure Wide Finder series that makes interesting
reading.
The best thing about Clojure is the immediacy and ability to syntax
check
as you go. I'm using TextMate with the Clojure bundle and it's working
great,
just hit clover-R on hightlighted text and the result comes right
back...
In short don't worry about monads... The terminology is awful, and
they make
my head explode too.
Here's a nice little piece of code that sucks in a file and inserts it
into a SQL
table. This is the sort of conciseness I love about Clojure.
(defn load-records [table-name file-name]
(doseq [line (-> file-name java.io.FileReader.
java.io.BufferedReader. line-seq)]
(let [fields (map #(.replace %1 "~" "") (seq (.split #"\^" (str line
"~"))))]
(sql/insert-rows table-name fields))))
If this sucks as code, someone jump in and tell!
Best Wishes,
Jonathan
Very good. And so far, my experience has borne this out. It is
approachable, elegant, immediately usable. It's just that I am curious,
so I would like to be able to have at least a basic idea of what these
other conversations are about, even if I can't entirely follow every
argument.
> But seriously, in my personal opinion Monads are relatively useless in
> the context of Clojure. They are necessary in pure FP languages like
> Haskell because otherwise it's impossible get any real applications
> written. This is not to say they are not useful, you just don't need
> to know a damn thing about them to have fun in Clojure.
OK. That puts it a bit more in perspective. Also, once I was online
again, I reached for Wikipedia to see if I could find an article written
to be understood by those outside the field. Actually, the first two
paragraphs here were helpful to get at least a basic grasp of what
Monads are about:
http://en.wikipedia.org/wiki/Monad_(functional_programming)
The overview here is certainly more readable than the foldoc entry I
read, and it, in turn links to a page on monad as used in category
theory which is, I am sure, readable by mathematicians, but which again
left me scratching my head just as the foldoc entry had. So I guess
it's not so much FP that I find hard to grok as it is the math from
which it has borrowed some terminology.
> Having hacked on Clojure for a a year and half now I think the best
> approach is to learn those aspects of Clojure that are most useful to
> you. You certainly don't need to pick up everything at once. I still
> don't completely grok deftype/protocols or the more involved
> concurrency constructs. This hasn't stopped me from writing many
> useful programs.
Most useful to me, or at least most interesting ... I can't say that at
this point I can see where I'm going to use this. But it certainly *is*
intriguing ... including the bits that right now are a hard to follow at
least in part due to the unfamiliar terms.
> If you _do_ want to get deeper in Clojure's philosophy you can't beat
> Rich Hickey's Amazon Bookshelf.
I'm not sure at this point how deep I want to go. Nice resource, though.
Ben
Nice! I see there's a Ruby adaptation too, and *that*, at least, is
familiar ground.
Cheers,
Ben
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
> As others have mentioned, Haskell is heavy in its use of monads and many other algebraic structures. I don't know why the two languages feel so different with respect to the level of formalism you need to use them. But, Haskell is one of the most mind bending programming language there and well worth the study.
The difference is perhaps more in the community than in the language. But Haskell clearly shows its academic origins, whereas Clojure clearly shows the pragmatic attitude of its creator. I can appreciate both, being in the academic world but not in computer science - programming for me is mostly pragmatic rather than a research goal in itself.
Konrad.
I think we often get the impression that functional programming is
directly connected to monads, but in practical terms the important
concepts are pure functions and persistent immutable datastructures.
The learning curve when coming from an imperative language, lies (for
me at least) mostly in avoiding looping/mutation and thinking in terms
of purely functional constructs and sequences. The surprising thing
is, that 99% of your code then turns out to be immutable and where you
would normally introduce state, you now don't have to. There are of
course things like I/O which are inherently stateful.
So long story short, read anyone of the many interesting blog posts
floating around on how to tackle real world problems using idiomatic
Clojure and you should be able to quickly grasp the jargon and
terminology. In my opinion you can entirely dismiss monads for the
first year or so of your Clojure experience.
If I'm over simplifying, feel free to correct me :)
Lau
On 17 Mar., 13:28, Ben Armstrong <synerg...@gmail.com> wrote:
> I am new to clojure and functional programming, but not to programming
> in general, having been in the profession for a quarter of a century.
> I'm trying to stretch myself a bit by learning clojure, but some of the
> threads here go beyond mere stretching to verge on head-exploding. In
> my offline reading of this list this morning, I tried using the tools
> available to me at the time (dict client and a few dictionaries like
> foldoc) to make sense of words like: http://foldoc.org/monad. I
There's a really nice article series on monads in Clojure:
http://onclojure.com/2009/03/05/a-monad-tutorial-for-clojure-programmers-part-1/
Also the "Learn you a Haskell for Great Good" tutorial is a pretty
nice and light-hearted introduction to FP with Haskell which might
also help you to understand some of the concepts better:
Michael
Oh, wow! Lucidly written. And it gives me something, maybe-m, that I
can't believe I got along without before. I'm eager now to continue
with part 2 ...
> Also the "Learn you a Haskell for Great Good" tutorial is a pretty
> nice and light-hearted introduction to FP with Haskell which might
> also help you to understand some of the concepts better:
>
> http://learnyouahaskell.com/
>
I've filed this one away. I had better stick with clojure for now until
I get more comfortable with it. Thanks. :)
Ben
> http://peepcode.com/products/functional-programming-with-clojure
Also the "Learn you a Haskell for Great Good" tutorial is a pretty
nice and light-hearted introduction to FP with Haskell which might
also help you to understand some of the concepts better:
http://learnyouahaskell.com/
Agreed. :-)
Well, I almost gave in to an urge to go on musing about FP in general,
but I decided to suppress it for now and to post instead my own short
bibliography of monad-related Web resources. Clojure-based stuff comes
first, though I'm also including two Haskell links of particular
interest. Michael has already mentioned Konrad's tutorial, but it is
still included below so that I can use this posting as a
self-contained reference.
Clearly it is true that there is no need to learn about monads to
programme in Clojure (and to be productive and have fun while doing
so), but they do make for a very interesting approach to structuring
computations, so if one is already curious about them, then one cannot
go wrong with some monadic food for thought. ;-) (The full immersion
programme is run in Haskell, of course, but the Clojure experience is
very enlightening too.)
All the best,
Michał
Monads: A Bibliography
=================
First, the above mentioned tutorial by Konrad Hinsen:
[A Monad Tutorial For Clojure Programmers][1]
The following articles by Jim Duey are also very good (and they do
take a somewhat different approach to Konrad's tutorial, so it's worth
while to read both series):
[Monads in Clojure][2]
[Higher Level Monads][3]
[Why Use Monads][4]
[The Continuation Monad in Clojure][5]
[Sessions for Compojure][6]
There's also a very good Haskell resource on the most frequently used monads:
[All About Monads][7]
The example code is in Haskell, but each monad's section includes some
motivating discussion.
Then there are [Philip Wadler's monad-related papers][8]. IIRC,
"Monads for functional programming" is a bit of a tutorial paper, so
that may be worth skimming.
And just for the pleasure of reading through the numerous displays of
breathtaking FP brilliance collected therein, take a look at [Oleg
Kiselyov's site][9]. The section labelled "Computation" has a
subsection devoted to monads.
[1]: http://onclojure.com/2009/03/05/a-monad-tutorial-for-clojure-programmers-part-1/
[2]: http://intensivesystems.net/tutorials/monads_101.html
[3]: http://intensivesystems.net/tutorials/monads_201.html
[4]: http://intensivesystems.net/tutorials/why_monads.html
[5]: http://intensivesystems.net/tutorials/cont_m.html
[6]: http://intensivesystems.net/tutorials/web_sessions.html
[7]: http://www.haskell.org/all_about_monads/html/index.html
[8]: http://homepages.inf.ed.ac.uk/wadler/topics/monads.html
[9]: http://okmij.org/ftp/
(def true-or-false (constantly (either true false)))
;; computes subseqs in the seq monad and subsets in the set monad
(defn subs [s]
(m-filter true-or-false s)))
(defn partitions [s]
(m-partition-by true-or-false s))
(def permutations [s]
(when (seq s)
(>> (permutations (rest s))
[[left right] (m-split-with true-or-false %)]
(concat left [(first s)] right))))
You could respond that most of the heavy lifting is done by the
monadic transliterations of commonplace seq functions like filter,
partition-by and split-with. You would be right; that is the whole
point.
Anyway, you certainly don't need to know any of this stuff to code
Clojure, and I do agree that is a strength of the language compared
to, say, Haskell.
-Per