micha | 1 Mar 2007 10:46
Picon
Favicon

phantom type thing question


I'm getting confused while trying to implement some subtyping hierachy 
with polymorphic variants.
say I have the hierachy:

symbol -> image -> xpmimage

and types like that:

type 'a sym;;

make_symbol : params -> [`Symbol] sym;;
make_image: params -> [`Image] sym;;

or should it be:
make_image: params -> [`Symbol | `Image] sym;;
make_xpm; params -> [`Symbol | `Image | `Xpm ] sym;;

so that some functions work only on some symbols:

val get_image_width: [< `Image | `XpmImage] sym -> int;;

I think I mix up the [< ..] and [> ... ] type constructs, allthough I 
thought I understood it :-)

 Michael

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
(Continue reading)

Olivier Andrieu | 1 Mar 2007 14:49
Favicon

Re: phantom type thing question

On 3/1/07, micha <micha-1 <at> fantasymail.de> wrote:
>
> I'm getting confused while trying to implement some subtyping hierachy
> with polymorphic variants.
> say I have the hierachy:
>
> symbol -> image -> xpmimage
>
> and types like that:
>
> type 'a sym;;

if you want subtyping, you'll need to add a variance annotation to
your type parameter. Otherwise since your type sym is abstract, you'll
get no subtyping at all. In this case you probably want a
contravariant type parameter:

type -'a sym

> make_image: params -> [`Symbol | `Image] sym;;
> make_xpm; params -> [`Symbol | `Image | `Xpm ] sym;;

you can define type names, this gives shorter definitions for deep hierarchies:

type symbol = [`Symbol]
type image = [symbol | `Image]
type xpm   = [image | `Xpm]

make_xpm : params -> xpm sym

(Continue reading)

Jacques Garrigue | 1 Mar 2007 15:08
Picon

Re: Some labltk widgets missing

From: Satoshi Fujiwara <fujitets <at> w2.dion.ne.jp>
> Let me ask another question.
> # Maybe it's a FAQ...
> 
> Why camltk and labltk both exists?
> These look like twins for me.
> What is the role of these two libraries?
> (I think if there is no need to use the camltk...)

The original library was CamlTk, and LablTk was actually created by
hacking the automatic generation tool included in CamlTk.

As a result, for a long time only CamlTk was available, and for
instance the MMM web browser was developped using CamlTk. Many
examples are available, and CamlTk is described in one of the rare
books on OCaml written in English.

For all these reasons, it is necessary to continue supporting it, and
the current implementation does it at a very low cost, by using the
same backend.

Jacques Garrigue

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

(Continue reading)

Satoshi Fujiwara | 1 Mar 2007 14:33
Picon

Re: Some labltk widgets missing

Hi,

Now I see. Thank you for your reply.

Let me ask another question.
# Maybe it's a FAQ...

Why camltk and labltk both exists?
These look like twins for me.
What is the role of these two libraries?
(I think if there is no need to use the camltk...)

Jacques Garrigue wrote:
> From: Satoshi Fujiwara <fujitets <at> w2.dion.ne.jp>
> 
>> Now I'm using 'labltk' with ocaml-3.09.3, and realized that
>> some widgets such as 'labelframe', 'spinbox', etc are missing.
>>
>> I like to using 'labltk' because it's easy to use, but
>> when I check the tk8.4's demo, I found many functions are
>> not supported in 'labltk'.
> 
> The widgets supported in camltk/labltk are those of tk8.0.
> New widgets were not added to keep compatibility, but since Tcl/Tk
> seems to have finally converged on 8.4, this might be a good idea to
> add the new widgets now. This is easy to do: mainly editing the
> Widgets.src file. But this is time consuming: one has to check by hand
> the Tcl/Tk documentation to find all the missing functions and
> parameters... So this will probably not be in 3.10.0, but could be
> done in a reasonably close future.
(Continue reading)

micha | 1 Mar 2007 17:40
Picon
Favicon

Re: phantom type thing question

Am Thu, 1 Mar 2007 14:47:47 +0100
schrieb "Olivier Andrieu" <oandrieu <at> gmail.com>:

> On 3/1/07, micha <micha-1 <at> fantasymail.de> wrote:
> >
> if you want subtyping, you'll need to add a variance annotation to
> your type parameter. Otherwise since your type sym is abstract, you'll
> get no subtyping at all. In this case you probably want a
> contravariant type parameter:
> 
> type -'a sym

o.k., but after reading section 6.8.1 of the manual I don't see why it
needs to be -'a and not +'a

> that should be:
> val get_image_width : [> xpm] sym -> int

thanks, that helped,

 Michael 

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

(Continue reading)

Olivier Andrieu | 1 Mar 2007 18:03
Favicon

Re: phantom type thing question

On 3/1/07, micha <micha-1 <at> fantasymail.de> wrote:
> Am Thu, 1 Mar 2007 14:47:47 +0100
> schrieb "Olivier Andrieu" <oandrieu <at> gmail.com>:
>
> > On 3/1/07, micha <micha-1 <at> fantasymail.de> wrote:
> > >
> > if you want subtyping, you'll need to add a variance annotation to
> > your type parameter. Otherwise since your type sym is abstract, you'll
> > get no subtyping at all. In this case you probably want a
> > contravariant type parameter:
> >
> > type -'a sym
>
> o.k., but after reading section 6.8.1 of the manual I don't see why it
> needs to be -'a and not +'a
>
>
> > that should be:
> > val get_image_width : [> xpm] sym -> int

your parameter encodes some "capabilities": you want the function
get_image_width to accept values that have the tag `xpm and possibly
more tags, hence the [> ] in the type of the function.
In other words, you want the type xpm sym to be a subtype of
[xpm|`xpm8] sym (for instance), so that get_image_width accept boths.
Since [xpm|`xpm8] is a subtype of xpm sym (the other way around), that
means the parameter needs to be contravariant.

_______________________________________________
Caml-list mailing list. Subscription management:
(Continue reading)

micha | 1 Mar 2007 21:01
Picon
Favicon

Re: phantom type thing question


thanks for the examples, I indeed thought the other way round :-)
It's clear now,

 Michael

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Sam Steingold | 1 Mar 2007 22:08
Picon

camlzip fails on a good (but large) file

I have a large .gz file (2264083417 bytes) which "gzip -t" report is valid.
trying to read it using camlzip results in
Fatal error: exception Gzip.Error("bad magic number, not a gzip file")
this is probably caused by integer overflow.
camlzip we have came with godi:
(* $Id: gzip.mli,v 1.2 2002/02/18 09:12:13 xleroy Exp $ *)
is this a known problem?

Sam

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Christophe Raffalli | 3 Mar 2007 10:20
Picon
Favicon

OCaml float size


Hello,

Does anyone knows of an architecture where OCaml floats have more than 
64 bits ? I have just one computation to run that requires more than 64 
bits ...
So getting a hand on such an architecture would be simpler that writing 
a library to access the Intel extended precision ...
Moreover, I would have to always box the extended with a big speed 
penalty ... and my computation is long (count in month !)

Thanks for any hint,
Christophe Raffalli

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Deokhwan Kim | 3 Mar 2007 15:59
Picon

The sharing mechanism in the Marshal module

Hello,

I thought the following code would produce 2 in (* 1 *), but as it is it
outputs 1:

let incr =
let c = ref 0 in
function () -> c:= !c + 1 ; !c

let save =
Marshal.to_string incr [Marshal.Closures]

let incr1 =
(Marshal.from_string save 0 : unit -> int)

let () =
Printf.printf "%d\n" (incr ()) ;
Printf.printf "%d\n" (incr1 ()) (* 1 *)

Why? In addtion, what should I do if I really want the sharing of the c
counter between incr and incr1?

Thanks.

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
(Continue reading)


Gmane