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 CAA17539; Tue, 4 Mar 2003 02:10:37 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA17950 for ; Tue, 4 Mar 2003 02:10:35 +0100 (MET) Received: from grace.speakeasy.org (grace.speakeasy.org [216.254.0.2]) by concorde.inria.fr (8.11.1/8.11.1) with SMTP id h241AXT10275 for ; Tue, 4 Mar 2003 02:10:34 +0100 (MET) Received: (qmail 24383 invoked by uid 36130); 4 Mar 2003 01:10:32 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 4 Mar 2003 01:10:32 -0000 Date: Mon, 3 Mar 2003 17:10:32 -0800 (PST) From: brogoff@speakeasy.net To: james woodyatt cc: The Trade Subject: Re: [Caml-list] extensional polymorphism In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam: no; 0.00; brogoff:01 caml-list:01 extensional:01 woodyatt:01 agitate:01 notations:01 monad:01 monads:01 monadic:01 haskell:01 wadler's:01 constrain:01 functors:01 val:01 ad-hoc:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 3 Mar 2003, james woodyatt wrote: > On Monday, Mar 3, 2003, at 12:10 US/Pacific, brogoff@speakeasy.net > wrote: > > > > That's why I said "Agitate for extensional polyorphism!". You really > > want a > > way to overload similar notations. > > If "extensional polymorphism" is what I want in order to be able to > define an operator ( >>= ) that performs the monad bind operation on > arbitrary monads, then yeah-- I'm all for it. > > I recently discovered the power of monadic programming, but I am in no > hurry to switch to Haskell in order to get a nice clean syntax for it. You can do a fair bit of monadic programming in OCaml now, using the module system. If you are interested, I'll show you, but you'll learn more by just translating Wadler's early papers into OCaml. If you want to do complicated monadics with several different monad types intertwined in the same section of code, that may be tricky. Also, OCaml is an imperative language, so you have lots of monads built in :-). One of the problems I have with Haskell is that while there are a few examples where it just suits the problem so well that the solution is magically concise and beautiful, I find that there are more places where the emphasis on purity transforms trivial programming problems into a PhD level research problems. > If "extensional polymorphism" will get me a cleaner syntax for monadic > programming without forcing me to give up all the things that make > Ocaml the best language in the universe for imperative programming, > then sign me up right here right now. > > How would extensional polymorphism get me what I want? It may ameliorate the problem I cited above in which you're juggling many monads in the same section of code and you don't want to use (module) qualified types to distinguish your bindMs and returnMs or whatever you want to call your operations. -- Brian PS: Here's a signature, use it to constrain modules, and use functors over these modules to express some monadic ops. module type MONAD = sig type 'a t val returnM : 'a -> 'a t val bindM : 'a t -> ('a -> 'b t) -> 'b t val mapM : ('a -> 'b) -> 'a t -> 'b t val joinM : 'a t t -> 'a t (* Ad-hoc show function *) val showM : 'a t -> ('a -> string) -> string end and a List monad module List_monad : MONAD = struct type 'a t = 'a list let returnM x = [x] let bindM m f = List.flatten (List.map f m) let mapM f m = List.map f m let joinM mm = List.flatten mm let showM m f = List.fold_right (fun x s -> if s = "" then (f x) ^ s else (f x) ^ "; " ^ s) m "" end ------------------- 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