caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: brogoff@speakeasy.net
To: james woodyatt <jhw@wetware.com>
Cc: The Trade <caml-list@inria.fr>
Subject: Re: [Caml-list] extensional polymorphism
Date: Mon, 3 Mar 2003 17:10:32 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.44.0303031649160.9492-100000@grace.speakeasy.net> (raw)
In-Reply-To: <C62BDE26-4DC0-11D7-A907-000393BA7EBA@wetware.com>

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


  reply	other threads:[~2003-03-04  1:10 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-03 18:28 [oliver: Re: [Caml-list] Strings as arrays or lists...] Oliver Bandel
2003-03-03 20:10 ` brogoff
2003-03-03 21:05   ` William Lovas
2003-03-03 21:32     ` Basile STARYNKEVITCH
2003-03-03 22:10     ` [Caml-list] [RANT] String representation (was: Strings as arrays or lists...) Nicolas George
2003-03-04 12:43       ` Diego Olivier Fernandez Pons
2003-03-04 16:14         ` William D. Neumann
2003-03-04 18:38           ` Xavier Leroy
2003-03-04 18:50             ` William D. Neumann
2003-03-04 19:01         ` Nicolas George
     [not found]       ` <Pine.A41.4.44.0303041312560.4431978-100000@ibm1.cicrp.juss ieu.fr>
2003-03-04 13:49         ` David Chase
2003-03-04  0:20     ` [oliver: Re: [Caml-list] Strings as arrays or lists...] Issac Trotts
2003-03-04  0:24       ` Alain.Frisch
2003-03-04  1:06         ` Issac Trotts
2003-03-04  0:39       ` Olivier Andrieu
2003-03-04  0:39     ` brogoff
2003-03-03 21:40   ` [Caml-list] extensional polymorphism james woodyatt
2003-03-04  1:10     ` brogoff [this message]
2003-03-04  2:04       ` james woodyatt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.44.0303031649160.9492-100000@grace.speakeasy.net \
    --to=brogoff@speakeasy.net \
    --cc=caml-list@inria.fr \
    --cc=jhw@wetware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).