From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA29625; Wed, 12 Mar 2003 21:50:08 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA32212 for ; Wed, 12 Mar 2003 21:50:07 +0100 (MET) Received: from viola.sinor.ru (viola.sinor.ru [217.70.106.9]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h2CKo6X04985 for ; Wed, 12 Mar 2003 21:50:06 +0100 (MET) Received: from sibnet.ru (tlg5-ppp36.sibnet.ru [217.70.116.36]) by viola.sinor.ru (8.12.8/8.12.3) with ESMTP id h2CKo1du017106 for ; Thu, 13 Mar 2003 02:50:02 +0600 Received: by sibnet.ru id m18tD2v-001EpaC; Thu, 13 Mar 2003 02:41:53 +0600 (NOVT) Date: Thu, 13 Mar 2003 02:41:53 +0600 From: Max Kirillov To: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] OCaml popularity (long!) Message-ID: <20030313024153.B748@max.home> References: <005d01c2e76f$92d0f8b0$2713f9ca@WARP> <20030311162627.GA32188@ontosoft.com> <3E6DDAFC.19000.44771B6@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <3E6DDAFC.19000.44771B6@localhost>; from mgushee@havenrock.com on Tue, Mar 11, 2003 at 12:47:56PM -0700 X-Sender: Max X-Spam: no; 0.00; kirillov:01 caml-list:01 mgushee:01 havenrock:01 haskell:01 monads:01 introductory:99 insists:01 monad:01 beginners:01 inlined:01 gong:99 succeeding:01 gushee:01 englewood:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, Mar 11, 2003 at 12:47:56PM -0700, mgushee@havenrock.com wrote: > My other big problem with Haskell was ... you guessed it: monads! I > must have read every introduction to monads that's available on line > (and there are at least half a dozen), but I still don't really > understand them. Without monads, you can't do any real work in > Haskell, and monads are universally acknowledged to be a difficult > concept. Yet every introductory text I have seen on Haskell insists > that you learn the theory of monads before you can learn how to do > things like I/O. > > Since I don't understand monads, maybe I'm missing something, but > this insistence on theory before practice seems like pure dogma to > me. I've even seen two or three Haskell tutorials that open with > statements to the effect that "I could teach you how to write a > Hello, World program, but I won't, because then you wouldn't > understand why Haskell is so great." > > I don't buy that argument--at least I don't accept that it's > universally true. People have different learning styles, but many > learn best by doing. I don't know how typical I am, but I find that a > good experience working with a new language naturally leads to a > desire for deeper understanding. I wonder, why people are so troubled by monads. I suppose the answer is: bacause they try to "understand" it. But there are really nothing to understand! You don't need to have PhD in math or read Leibnitz to use the IO monad, and the IO monad is the only monad a beginner could need (list/maybe monads looks like just incidental thing to me; ST s monads are very similar to IO monads, and can, for a beginners, be replaced by it; the only I can recall now is monad of parsers, but, consider, it is not an introductory question at all). This is very simple: Values in haskell are not a "contents of variables" or omething like this; they are values in concept. Function (that is to produce them), can therefore be called just anytime compiler will decide it to do. They can be executed multiple time (e.g. when inlined) or not executed at all, when we don't need the value. Beacause of that, Haskell functions can not represent actions. Instead, that does values of type IO a. A notion "IO a" means "make something, and provide a [way to compute] value of type a". Note here: not "a -> IO b", but "IO a" -- action without an argument is quite meaningful thing. For example, (counter :: IO Integer) produces infinitely increasing numbers. (time :: IO Double) returns time in some units, or (is_connected :: IO Bool) reports, is, for example, our program connected to the server and so on. Gong back to ocaml, I would say that "IO a" is roughly equivalent to "unit -> 'a" (indeed, "(unit -> 'a Lazy.t) Lazy.t" would be more right). Now remember, have you ever had to add the "unit" argument to your ocaml functions (in fact, not very often -- since ocaml is strict, there's always a possibility to use some of real argument to trigger the execution). To use actions, there must be a way to combine them. There are operators ">>" and ">>=". The first combines two actions in an action, which is a sequence of them. The second form is intended to propagate the results of execution to the succeeding actions. It combnes an action of type IO a and function taking a value of type a and producing an action, which, when executed, first executes the first action, then takes it result, computes the second action and executes it. "do" notation inteded to make the sequences of action look similar to the imperative languages. Since a program is definetly an action, your main function must have type "IO something". It really does: "IO ()" -- takes nothing, doing something, produces nothing. That's just all. Is it so hard? > -- > Matt Gushee > Englewood, CO USA -- Max ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners