caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: "Re: [Caml-list] A G'Caml question" + additional info
@ 2001-07-11 14:30 Krishnaswami, Neel
  2001-07-11 16:22 ` Brian Rogoff
  0 siblings, 1 reply; 17+ messages in thread
From: Krishnaswami, Neel @ 2001-07-11 14:30 UTC (permalink / raw)
  To: caml-list

Sven [mailto:luther@dpt-info.u-strasbg.fr] wrote:
> On Tue, Jul 10, 2001 at 02:21:02PM -0400, Krishnaswami, Neel wrote:
> > 
> > Can you describe how I'd write something like the show function in 
> > Haskell, or the print-object generic function in Dylan? I've looked
> > at the G'Caml documentation, and it doesn't look like it's possible
> > to extend a generic function with new branches.
> 
> i think they are speacking about an extension to g'caml that 
> would use the include keyword and permit such extension.
> Please read the previous mails about this thread.

Ah, I misunderstood, then. I thought the claim was that include 
wouldn't be included, but that it wasn't necessary. 


--
Neel Krishnaswami
neelk@cswcasa.com
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 17+ messages in thread
* RE: "Re: [Caml-list] A G'Caml question" + additional info
@ 2001-07-16 18:24 John R Harrison
  0 siblings, 0 replies; 17+ messages in thread
From: John R Harrison @ 2001-07-16 18:24 UTC (permalink / raw)
  To: Markus Mottl; +Cc: caml-list, John Harrison


Markus Mottl writes:

| This is a shortcoming of the standard library that there are no
| polymorphic implementations of "Set" and similar. It's very easy to
| extract a polymorphic (module-) version from the existing code. 

I strongly agree with this point. From recent messages it seems that I'm
just one of a whole army of O'Caml users who've essentially
cut-and-pasted code out of the standard set library with a fixed
polymorphic comparison function inserted. For a polymorphic language to
make dealing with polymorphic sets so awkward seems ridiculous.

Perhaps the justification for the decision to include orderings in the
standard interface is that the default equality and orderings may not
behave as desired on arbitrary types, e.g. non-canonical abstract data
types like other sets. However, a better solution might be to make
equality on abstract types settable (see an earlier thread I started on
this topic). Will G'Caml be any help in this respect? That is, will it
allow one to "overload" equality on particular types?

John.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: "Re: [Caml-list] A G'Caml question" + additional info
@ 2001-07-10 18:21 Krishnaswami, Neel
  2001-07-11  6:09 ` Sven
  0 siblings, 1 reply; 17+ messages in thread
From: Krishnaswami, Neel @ 2001-07-10 18:21 UTC (permalink / raw)
  To: caml-list

Patrick M Doane [mailto:patrick@watson.org] wrote:
> 
> On Mon, 2 Jul 2001, Brian Rogoff wrote:
> 
> > I'm convinced that the include scheme, when properly integrated with
> > modules, will be sufficient. We need more experience with 
> > the current scheme. 
> 
> I'm convinced now too, it took me a day or two to think things over to
> come to the same conclusion. 

Can you describe how I'd write something like the show function in 
Haskell, or the print-object generic function in Dylan? I've looked
at the G'Caml documentation, and it doesn't look like it's possible
to extend a generic function with new branches.

--
Neel Krishnaswami
neelk@cswcasa.com
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 17+ messages in thread
[parent not found: <3B3D503C.E91DDE34@ozemail.com.au>]
[parent not found: <3B3BB6EC.3DEB6CBF@ozemail.com.au>]
* [Caml-list] A G'Caml question
@ 2001-06-20  3:16 Brian Rogoff
  2001-06-25 17:11 ` "Re: [Caml-list] A G'Caml question" + additional info Jun Furuse
  0 siblings, 1 reply; 17+ messages in thread
From: Brian Rogoff @ 2001-06-20  3:16 UTC (permalink / raw)
  To: caml-list

Hi,
    One of the important issues with overloading is whether one has 
to define a "generic" function all in one place or if you can build it up 
piecemeal from already existing generic functions. I played a bit, learned 
some things, and now I have some questions. 

I start with the obvious "plus" function, and extend it so that in 
concatenates strings. 

# generic plus = case
    int -> int -> int => (+)
  | float -> float -> float => (+.) ;;  
val plus : $a -> $a -> $a [ int -> int -> int 
                          | float -> float -> float  ] =
  <fun>
# plus 1 2;;
- : int = 3
# plus 1.0 2.0;;
- : float = 3
# plus "1" "2";;
This generic full instance is used with type string -> string -> string
 which is not its valid instance of 
$a -> $a -> $a [ int -> int -> int 
               | float -> float -> float  ]
# generic plus = case 
  string -> string -> string => (^) 
  | $a -> $a -> $a => plus ;;  
val plus : $a -> $a -> $a
  [ string -> string -> string 
  | $a -> $a -> $a && plus : $a -> $a -> $a  ] = <fun>
# plus 1 1;;
- : int = 2
# plus "1" "2.0";;
- : string = "12.0"

Cool, for some very simple cases, it we can incrementally build up a 
generic function from pieces. I think it's obvious that we'll get into 
trouble with recursive generics. 

# generic rec print = case 
  | int -> unit => print_int
  | string -> unit => print_string
  | $a list -> unit => 
      function [] -> ()
      |   x :: xs -> print x; print xs
  ;;            
  val print : $a -> unit
  [ int -> unit 
  | string -> unit 
  | $a list -> unit && print : $a -> unit && print : $a list -> unit  ] =
  <fun>
# print 23;;
23- : unit = ()
# print 23.0;;
This generic full instance is used with type float -> unit
 which is not its valid instance of 
$a -> unit
[ int -> unit 
| string -> unit 
| $a list -> unit && print : $a -> unit && print : $a list -> unit  ]

OK, lets try the same thing as before, 

# generic rec print = case float -> unit => print_float | $a -> unit =>
print;;
val print : $a -> unit
  [ float -> unit 
  | $a -> unit && print : $a -> unit  ] = <fun>

# print 1.0;;
1- : unit = ()
# print 1 (* infinite loop! *)

Well, that should be expected, since we try and print an int, which isn't
a float, so we try (from $a -> unit => print) to print, ad infinitum. Is
there a way out? If we try and rename print and call that, it still won't work, 
since we want a form of "open recursion" here: if I add a case for float I 
want to be able to print float lists. With the original print
reinstalled...

# let print' = print ;;
val print' : $a -> unit [ $a -> unit && print : $a -> unit  ] = <fun>
# generic rec print = case float -> unit => print_float | $a -> unit =>
print';;
val print : $a -> unit
  [ float -> unit 
  | $a -> unit && print' : $a -> unit  ] = <fun>
# print 1.0;;
1- : unit = ()
# print [1;2;3];;
123- : unit = ()
# print [1.0;2.0;3.0];; 
This generic full instance is used with type float list -> unit
 which is not its valid instance of 
$a -> unit [ float -> unit 
           | $a -> unit && print' : $a -> unit  ]

Is there some trick to build up recursive generics by parts? One thing 
to do is to break the recursive generic into a non-recursive generic
and a recursive function which applies the generic to the elements, 
but that feels like cheating. Maybe open recursion for generics would 
be desirable, so that I can add a new case and have the recursive call in 
an existing case call the new one? Yes, it's a half baked idea, but maybe 
a better cook can finish baking...

-- Brian



-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2001-07-16 20:35 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-11 14:30 "Re: [Caml-list] A G'Caml question" + additional info Krishnaswami, Neel
2001-07-11 16:22 ` Brian Rogoff
2001-07-11 16:35   ` Bruce Hoult
2001-07-11 19:12     ` Markus Mottl
2001-07-12  3:15   ` Patrick M Doane
  -- strict thread matches above, loose matches on Subject: below --
2001-07-16 18:24 John R Harrison
2001-07-10 18:21 Krishnaswami, Neel
2001-07-11  6:09 ` Sven
     [not found] <3B3D503C.E91DDE34@ozemail.com.au>
2001-06-30 16:01 ` Patrick M Doane
2001-06-30 20:59   ` Brian Rogoff
2001-07-01  5:32     ` Patrick M Doane
2001-07-02 15:55       ` Brian Rogoff
2001-07-10 18:08         ` Patrick M Doane
     [not found] <3B3BB6EC.3DEB6CBF@ozemail.com.au>
2001-06-29  4:18 ` Patrick M Doane
2001-06-20  3:16 [Caml-list] A G'Caml question Brian Rogoff
2001-06-25 17:11 ` "Re: [Caml-list] A G'Caml question" + additional info Jun Furuse
2001-06-28  2:21   ` Patrick M Doane
2001-06-28  4:40     ` Brian Rogoff

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).