caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Yelling
@ 2003-04-23 14:16 Eray Ozkural
  2003-04-23 14:56 ` Neel Krishnaswami
  0 siblings, 1 reply; 7+ messages in thread
From: Eray Ozkural @ 2003-04-23 14:16 UTC (permalink / raw)
  To: caml-list

Hey, somebody yell if you've been able to use the digraph and dynarray code I 
posted earlier! I'd also love to have wishlists!!!

Some other things I forgot to mention: An undirected graph adaptor is easy. I 
initially started with a vertex/edge weighted graph... Also I plan to 
functor-ize the graph modules making it more generic, ultimately the 
representation should be abstracted away completely. Then you have classes, 
oops, modules that have different time/space complexities for storage and 
update, query operations....

BTW, does somebody have a good idea of how to make one module inherit from 
another? Say, for implementing Graph using Digraph. It's too bad there isn't 
an Ada like package extension mechanism.

Cheers,


-- 
Eray Ozkural (exa) <erayo@cs.bilkent.edu.tr>
Comp. Sci. Dept., Bilkent University, Ankara  KDE Project: http://www.kde.org
www: http://www.cs.bilkent.edu.tr/~erayo  Malfunction: http://mp3.com/ariza
GPG public key fingerprint: 360C 852F 88B0 A745 F31B  EA0F 7C07 AE16 874D 539C

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


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

* Re: [Caml-list] Yelling
  2003-04-23 14:16 [Caml-list] Yelling Eray Ozkural
@ 2003-04-23 14:56 ` Neel Krishnaswami
       [not found]   ` <3EA6AB00.7020305@post.tepkom.ru>
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Neel Krishnaswami @ 2003-04-23 14:56 UTC (permalink / raw)
  To: caml-list

Eray Ozkural writes:
> 
> BTW, does somebody have a good idea of how to make one module
> inherit from another? Say, for implementing Graph using
> Digraph. It's too bad there isn't an Ada like package extension
> mechanism.

You can pretty easily simulate the effect of this kind of inheritance
using the module system, but it's a moderate pain.

First, I'll talk about module signatures. Signatures have a structural
subtyping relationship -- signature BAR is a subtype of FOO if it
supports all of FOO's interface. It is permitted to offer more
operations, but must include all of FOO's types and values. Then you
can use a module of signature BAR wherever a FOO is expected. Here's
an example:

  module type FOO =
    sig
      type t
      val v : t
    end
  
  module type BAR = (* This is a subtype of FOO *)
    sig
      type t
      val v : t
      val v' : t
    end

Notice that there's no syntax to abbreviate the definition of BAR; you
need to manually include all of the types and operations in it. This
will be your main annoyance, but for a closed library it's tolerable.

Happily, there is syntax to abbreviate the *implementation* of module
extensions. You can implement one module, and then use the include
keyword to add its types and bindings to some other module. For
example:
  
  module Foo : FOO =
    struct
      type t = Foo of unit
  
      let v = Foo()
    end
  
  module Bar : BAR with type t = Foo.t =
    struct
      include Foo (* Add the type t and value v to the Foo module *)
  
      let v' = v
    end

The "with type t = Foo.t" thing at the top of Bar is a sharing
declaration. It informs the compiler that the type Bar.t is the same
as the type Foo.t, so you can freely intermix Foo.t and Bar.t values.
(Otherwise the compiler would forbid it, on the grounds that these are
two different abstract types.)

I hope this helps! 

-- 
Neel Krishnaswami
neelk@alum.mit.edu

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


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

* Re: [Caml-list] Yelling
       [not found]   ` <3EA6AB00.7020305@post.tepkom.ru>
@ 2003-04-23 15:31     ` Neel Krishnaswami
  2003-04-23 15:50       ` Eray Ozkural
  2003-04-24  7:58       ` Hendrik Tews
  0 siblings, 2 replies; 7+ messages in thread
From: Neel Krishnaswami @ 2003-04-23 15:31 UTC (permalink / raw)
  To: caml-list


Anton Moscal writes:
>
> This isn't true: you can abbrevaite the later declaration as:
>    module type BAR = (* This is a subtype of FOO *)
>      sig
>        include FOO
>        val v' : t
>      end
> 
> AFAIK this is not documented and relatively new feature, but its
> works.

I just tried this out, and it's really cool!

Are there any plans to document this feature and make it permanent?
If so, I might try functorizing Haskell's Edison data structure
libraries (the endless copying of interfaces was the reason I gave up
the last time I tried this).

-- 
Neel Krishnaswami
neelk@alum.mit.edu

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


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

* Re: [Caml-list] Yelling
  2003-04-23 14:56 ` Neel Krishnaswami
       [not found]   ` <3EA6AB00.7020305@post.tepkom.ru>
@ 2003-04-23 15:33   ` Andreas Rossberg
  2003-04-23 15:56   ` Eray Ozkural
  2 siblings, 0 replies; 7+ messages in thread
From: Andreas Rossberg @ 2003-04-23 15:33 UTC (permalink / raw)
  To: caml-list; +Cc: Neel Krishnaswami

Neel Krishnaswami wrote:
> 
>   module type FOO =
>     sig
>       type t
>       val v : t
>     end
>   
>   module type BAR = (* This is a subtype of FOO *)
>     sig
>       type t
>       val v : t
>       val v' : t
>     end
> 
> Notice that there's no syntax to abbreviate the definition of BAR;

Sure there is:

    module type BAR =
      sig
        include FOO
        val v' : t
      end

should work like a charm. ;-)

-- 
Andreas Rossberg, rossberg@ps.uni-sb.de

"Computer games don't affect kids; I mean if Pac Man affected us
  as kids, we would all be running around in darkened rooms, munching
  magic pills, and listening to repetitive electronic music."
  - Kristian Wilson, Nintendo Inc.

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


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

* Re: [Caml-list] Yelling
  2003-04-23 15:31     ` Neel Krishnaswami
@ 2003-04-23 15:50       ` Eray Ozkural
  2003-04-24  7:58       ` Hendrik Tews
  1 sibling, 0 replies; 7+ messages in thread
From: Eray Ozkural @ 2003-04-23 15:50 UTC (permalink / raw)
  To: Neel Krishnaswami, caml-list

On Wednesday 23 April 2003 18:31, Neel Krishnaswami wrote:
> Anton Moscal writes:
> >    module type BAR = (* This is a subtype of FOO *)
> >      sig
> >        include FOO
            ^^^^^^^^^^^^^  w00t!!
> >        val v' : t
> >      end
-- 
Eray Ozkural (exa) <erayo@cs.bilkent.edu.tr>
Comp. Sci. Dept., Bilkent University, Ankara  KDE Project: http://www.kde.org
www: http://www.cs.bilkent.edu.tr/~erayo  Malfunction: http://mp3.com/ariza
GPG public key fingerprint: 360C 852F 88B0 A745 F31B  EA0F 7C07 AE16 874D 539C

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


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

* Re: [Caml-list] Yelling
  2003-04-23 14:56 ` Neel Krishnaswami
       [not found]   ` <3EA6AB00.7020305@post.tepkom.ru>
  2003-04-23 15:33   ` Andreas Rossberg
@ 2003-04-23 15:56   ` Eray Ozkural
  2 siblings, 0 replies; 7+ messages in thread
From: Eray Ozkural @ 2003-04-23 15:56 UTC (permalink / raw)
  To: Neel Krishnaswami; +Cc: caml-list


Just what I was looking for (^_^)

I didn't know of this syntax. I used functors here and there but I'm not too 
experienced in using signatures yet. I'm relatively new to ocaml and 
therefore constantly seeing things that surprise me!

Thanks!

On Wednesday 23 April 2003 17:56, Neel Krishnaswami wrote:
>   module Foo : FOO =
>     struct
>       type t = Foo of unit
>
>       let v = Foo()
>     end
>
>   module Bar : BAR with type t = Foo.t =
>     struct
>       include Foo (* Add the type t and value v to the Foo module *)
>
>       let v' = v
>     end
>
> The "with type t = Foo.t" thing at the top of Bar is a sharing
> declaration. It informs the compiler that the type Bar.t is the same
> as the type Foo.t, so you can freely intermix Foo.t and Bar.t values.
> (Otherwise the compiler would forbid it, on the grounds that these are
> two different abstract types.)
>
> I hope this helps!

-- 
Eray Ozkural (exa) <erayo@cs.bilkent.edu.tr>
Comp. Sci. Dept., Bilkent University, Ankara  KDE Project: http://www.kde.org
www: http://www.cs.bilkent.edu.tr/~erayo  Malfunction: http://mp3.com/ariza
GPG public key fingerprint: 360C 852F 88B0 A745 F31B  EA0F 7C07 AE16 874D 539C

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


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

* Re: [Caml-list] Yelling
  2003-04-23 15:31     ` Neel Krishnaswami
  2003-04-23 15:50       ` Eray Ozkural
@ 2003-04-24  7:58       ` Hendrik Tews
  1 sibling, 0 replies; 7+ messages in thread
From: Hendrik Tews @ 2003-04-24  7:58 UTC (permalink / raw)
  To: caml-list

   
   Anton Moscal writes:
   >
   > This isn't true: you can abbrevaite the later declaration as:
   >    module type BAR = (* This is a subtype of FOO *)
   >      sig
   >        include FOO
   >        val v' : t
   >      end
   > 
   > AFAIK this is not documented and relatively new feature, but its
   > works.
   
It's documented! See 6.10, last line of the grammar for
specification in the ocaml docs.

Bye,

Hendrik

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


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

end of thread, other threads:[~2003-04-24  7:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-23 14:16 [Caml-list] Yelling Eray Ozkural
2003-04-23 14:56 ` Neel Krishnaswami
     [not found]   ` <3EA6AB00.7020305@post.tepkom.ru>
2003-04-23 15:31     ` Neel Krishnaswami
2003-04-23 15:50       ` Eray Ozkural
2003-04-24  7:58       ` Hendrik Tews
2003-04-23 15:33   ` Andreas Rossberg
2003-04-23 15:56   ` Eray Ozkural

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