From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.9 required=5.0 tests=AWL,DNS_FROM_RFC_POST, HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 41E22BC37 for ; Sun, 11 Oct 2009 21:57:29 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AloEAOLV0UrRVd3DkGdsb2JhbACCIzAtjFSKeT8BAQEBCQkMBxMDq0wBBY1VAQaELQ X-IronPort-AV: E=Sophos;i="4.44,542,1249250400"; d="scan'208";a="38023422" Received: from mail-qy0-f195.google.com ([209.85.221.195]) by mail1-smtp-roc.national.inria.fr with ESMTP; 11 Oct 2009 21:57:28 +0200 Received: by qyk33 with SMTP id 33so8193260qyk.29 for ; Sun, 11 Oct 2009 12:57:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=yuNFKGGZ9dBm0l8jxVEBeDL3i3aJLfLHVxsoFu9bZgA=; b=P1o8oxkTmB77oxF6s4dYdemym4PtAzI2ahqefkPs5ccrx7CWEdeJYkCVXJj2wKQ0iW Pj0uupIKjzIWMnPGQNO4Y54O5/f9VsHpR9BY7Bt8dP09zOmnI4qCqkGFhW49r5DmJyLM lVY6zr1U2WYvC0hbkNIp/dMNhZ/TR0q2QfKFE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=aZ24Ick3hE2y7EGmjT5WpNI8mDxSdAToQlv9eZr8qbqYlZnb2XISpLLq1DyrIaKqAH Xod70y4Xv9nCQvTGqqiB0atWu1Pg/uw3SLfgkqx9HoTATNbFzbLP/IymOuPueAuFim+1 bEbfhWbrzHUiI13NL1pPPQxFLyK83H+UKIH6M= MIME-Version: 1.0 Received: by 10.229.15.203 with SMTP id l11mr2176489qca.43.1255291046026; Sun, 11 Oct 2009 12:57:26 -0700 (PDT) In-Reply-To: <5160b4200910110824q7998f43ao3d00e94ba7e74b2b@mail.gmail.com> References: <891bd3390910081840p37e8c786g60b2c15d2c06ae60@mail.gmail.com> <891bd3390910081853m5409c871y35495c6f16e180aa@mail.gmail.com> <5160b4200910110757y47ffad15v70434418cba61f26@mail.gmail.com> <62B782AA-1F44-4207-B037-5C6D1F6CBF50@gmail.com> <5160b4200910110824q7998f43ao3d00e94ba7e74b2b@mail.gmail.com> Date: Sun, 11 Oct 2009 12:57:25 -0700 Message-ID: <605bf2750910111257h1b2b3f31me95be82ba73b65a3@mail.gmail.com> Subject: Re: [Caml-list] Re: Improving OCaml's choice of type to display From: Gilles Pirio To: "caml-list@yquem.inria.fr" Content-Type: multipart/alternative; boundary=0015175ce094e35efb0475ae3841 X-Spam: no; 0.00; ocaml's:01 ocaml:01 val:01 extensively:01 furuse:01 furuse:01 struct:01 struct:01 avoided:01 yaron:01 minsky:01 yminsky:01 yaron:01 minsky:01 hashtbl:01 --0015175ce094e35efb0475ae3841 Content-Type: text/plain; charset=ISO-8859-1 On the same topic, I was wondering why the type of the ampl_scalar_app function below was displayed as ('a -> 'a -> float) -> 'a -> 'a -> float rather than ('a -> 'a -> float) -> 'a -> ('a -> float). The latter would make my life easier. # let ampl_scalar_app f p = if f p p > 1. then fun x->f x p else fun x->f p x;; val ampl_scalar_app : ('a -> 'a -> float) -> 'a -> 'a -> float = PS: I can imagine this has been discussed extensively before, feel free to just send my a link to the relevant discussion if that's the case :) Giles On Sun, Oct 11, 2009 at 8:24 AM, Jun Furuse wrote: > I have not tested it well but it counts dots and should try to find > the minimal one. > > A problem I have found so far is that it prints something confusing, ex. > > module M = struct type t end > module N = struct type t end > open M > open N > > let _ = ( 1 : M.t ) > > >> Error: This expression has type int but an expression was expected of > type t (which t ?!?!?) > > If there are types M.t and N.t and the both of M and N are opened, > these types are printed just "t". This can be avoided by testing the > result name "t" against the current typing envrionment to see it > really means the original type "M.t". This requires more coding but > the weekend has ended in the far east already :-) (It's 0:24 Monday > now.) > > Jun > > On Mon, Oct 12, 2009 at 12:12 AM, Yaron Minsky wrote: > > Cool! That was quick. > > > > Does this patch also implement stephen's fewest-number-of-dots heuristic? > I > > was thinking one nice approach would be fewest-number-of-dots with ties > > broken by length of final identifier. > > > > Y > > > > Yaron Minsky > > > > On Oct 11, 2009, at 10:57 AM, Jun Furuse wrote: > > > >> I have quickly wrote a small patch against 3.11.1 for this feature, to > >> see what it would be like. > >> > >> > http://sites.google.com/a/furuse.info/jun/hacks/other-small-ocaml-patches > >> > >> With this patch, path names are printed without opened modules in the > >> context. It also tries heuristic data type name simplification: if a > >> variant/record data type is an alias of another data type whose name > >> is shorter than the original, the printer uses the latter. > >> > >> For example: > >> > >> # open Hashtbl;; > >> # let tbl = Hashtbl.create 10;; > >> val tbl : ('_a, '_b) t = (* not Hashtbl.t, since Hashtbl is > >> open *) > >> > >> # type t = int;; > >> type t = int > >> # type long_name = int;; > >> type long_name = int > >> # (1 : t);; > >> - : t = 1 (* t is the shorter than its original type > >> int *) > >> # (1 : long_name);; > >> - : int = 1 (* int is shorter name for long_name. t > >> is even shorter but not aliased unfortunatelly. *) > >> > >> I warn you that the patch is very quickly written and not tested well. > >> Enjoy! > >> > >> Jun > >> > >> On Fri, Oct 9, 2009 at 10:53 AM, Yaron Minsky > wrote: > >>> > >>> And you can compete to come up with the most innocuous code that comes > up > >>> with the longest type. Here's my current favorite: > >>> > >>> # open Option.Monad_infix;; > >>> # Map.find m 3 >>| fun x -> x + 1;; > >>> - : int Core.Std.Option.Monad_infix.monad = Some 4 > >>> > >>> Which of course could be rendered as: > >>> > >>> # open Option.Monad_infix;; > >>> # Map.find m 3 >>| fun x -> x + 1;; > >>> - : int option = Some 4 > >>> > >>> y > >>> > >>> On Thu, Oct 8, 2009 at 9:40 PM, Yaron Minsky > wrote: > >>>> > >>>> Anyone who plays around with the Core library that Jane Street just > >>>> released can see showcased a rather ugly detail of how Core's design > >>>> interacts with how OCaml displays types. Witness: > >>>> > >>>> # Int.of_string;; > >>>> - : string -> Core.Std.Int.stringable = > >>>> # Float.of_string;; > >>>> - : string -> Core_extended.Std.Float.stringable = > >>>> > >>>> I'd be much happier if this was rendered in the following equally > >>>> correct > >>>> and more readable form: > >>>> > >>>> # Int.of_string;; > >>>> - : string -> Int.t = > >>>> # Float.of_string;; > >>>> - : string -> Float.t = > >>>> > >>>> Or even: > >>>> > >>>> # Int.of_string;; > >>>> - : string -> int = > >>>> # Float.of_string;; > >>>> - : string -> float = > >>>> > >>>> And this isn't just an issue in the top-level. The compiler also > >>>> displays > >>>> types in the same difficult to read form. I'm wondering if anyone has > >>>> some > >>>> thoughts as to what we can do to make the compiler make better choices > >>>> here. There are two issues to overcome: > >>>> > >>>> Dropping the module name. I'd love to give the compiler the hint that > >>>> Core.Std. could be dropped from the prefix in a context where that > >>>> module is > >>>> open. This is what's done with the pervasives module already, I > >>>> believe, so > >>>> it seems like it should be doable here. > >>>> Choosing shorter names. This one seems harder, but there are various > >>>> different possibilities for what type name to print out, and a > >>>> reasonable > >>>> heuristic to use might be to pick the shortest one. Part of the > reason > >>>> these issues come up is our use of standardized interface components > >>>> (that's > >>>> where the "stringable" type name comes from). I suspect this one will > >>>> be > >>>> hard to fix, sadly. > >>>> > >>>> Anyway, we'd be happy with any suggestions on how to improve matters. > >>>> > >>>> y > >>> > >>> > >>> _______________________________________________ > >>> 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 > >>> > >>> > > > > _______________________________________________ > 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 > --0015175ce094e35efb0475ae3841 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On the same topic, I was wondering why the type of the ampl_scalar_app = function below was displayed as ('a -> 'a -> float) -> = 9;a -> 'a -> float rather than ('a -> 'a -> float) = -> 'a -> ('a -> float). The latter would make my life easi= er.

# let ampl_scalar_app f p =3D if f p p > 1. then fun x->f x p els= e fun x->f p x;;
val ampl_scalar_app : ('a -> 'a -> flo= at) -> 'a -> 'a -> float =3D <fun>

PS: I can = imagine this has been discussed extensively before, feel free to just send = my a link to the relevant discussion if that's the case :)

Giles


On Sun, Oct 11, 2009 at 8:2= 4 AM, Jun Furuse <jun.furuse@gmail.com> wrote:
I have not tested it well but it counts dots and should try to find
the minimal one.

A problem I have found so far is that it prints something confusing, ex.
module M =3D struct type t end
module N =3D struct type t end
open M
open N

let _ =3D ( 1 : M.t )

>> Error: This expression has type int but an expression was expected= of type t =A0 =A0(which t ?!?!?)

If there are types M.t and N.t and the both of M and N are opened,
these types are printed just "t". This can be avoided by testing = the
result name "t" against the current typing envrionment to see it<= br> really means the original type "M.t". This requires more coding b= ut
the weekend has ended in the far east already :-) =A0 (It's 0:24 Monday=
now.)

Jun

On Mon, Oct 12, 2009 at 12:12 AM, Yaron Minsky <yminsky@gmail.com> wrote:
> Cool! =A0That was quick.
>
> Does this patch also implement stephen's fewest-number-of-dots heu= ristic? =A0I
> was thinking one nice approach would be fewest-number-of-dots with tie= s
> broken by length of final identifier.
>
> Y
>
> Yaron Minsky
>
> On Oct 11, 2009, at 10:57 AM, Jun Furuse <jun.furuse@gmail.com> wrote:
>
>> I have quickly wrote a small patch against 3.11.1 for this feature= , to
>> see what it would be like.
>>
>> http://sites.google.com/a/furuse.info= /jun/hacks/other-small-ocaml-patches
>>
>> With this patch, path names are printed without opened modules in = the
>> context. It also tries heuristic data type name simplification: if= a
>> variant/record data type is an alias of another data type whose na= me
>> is shorter than the original, the printer uses the latter.
>>
>> For example:
>>
>> # open Hashtbl;;
>> # let tbl =3D Hashtbl.create 10;;
>> val tbl : ('_a, '_b) t =3D <abstr> =A0 =A0 =A0(* not= Hashtbl.t, since Hashtbl is
>> open *)
>>
>> # type t =3D int;;
>> type t =3D int
>> # type long_name =3D int;;
>> type long_name =3D int
>> # (1 : t);;
>> - : t =3D 1 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (* t is the sh= orter than its original type
>> int *)
>> # (1 : long_name);;
>> - : int =3D 1 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (* int is shorte= r name for long_name. t
>> is even shorter but not aliased unfortunatelly. *)
>>
>> I warn you that the patch is very quickly written and not tested w= ell.
>> Enjoy!
>>
>> Jun
>>
>> On Fri, Oct 9, 2009 at 10:53 AM, Yaron Minsky <yminsky@gmail.com> wrote:
>>>
>>> And you can compete to come up with the most innocuous code th= at comes up
>>> with the longest type. =A0Here's my current favorite:
>>>
>>> # open Option.Monad_infix;;
>>> # Map.find m 3 >>| fun x -> x + 1;;
>>> - : int Core.Std.Option.Monad_infix.monad =3D Some 4
>>>
>>> Which of course could be rendered as:
>>>
>>> # open Option.Monad_infix;;
>>> # Map.find m 3 >>| fun x -> x + 1;;
>>> - : int option =3D Some 4
>>>
>>> y
>>>
>>> On Thu, Oct 8, 2009 at 9:40 PM, Yaron Minsky <yminsky@gmail.com> wrote:
>>>>
>>>> Anyone who plays around with the Core library that Jane St= reet just
>>>> released can see showcased a rather ugly detail of how Cor= e's design
>>>> interacts with how OCaml displays types. =A0Witness:
>>>>
>>>> # Int.of_string;;
>>>> - : string -> Core.Std.Int.stringable =3D <fun> >>>> # Float.of_string;;
>>>> - : string -> Core_extended.Std.Float.stringable =3D &l= t;fun>
>>>>
>>>> I'd be much happier if this was rendered in the follow= ing equally
>>>> correct
>>>> and more readable form:
>>>>
>>>> # Int.of_string;;
>>>> - : string -> Int.t =3D <fun>
>>>> # Float.of_string;;
>>>> - : string -> Float.t =3D <fun>
>>>>
>>>> Or even:
>>>>
>>>> # Int.of_string;;
>>>> - : string -> int =3D <fun>
>>>> # Float.of_string;;
>>>> - : string -> float =3D <fun>
>>>>
>>>> And this isn't just an issue in the top-level. The com= piler also
>>>> displays
>>>> types in the same difficult to read form. =A0I'm wonde= ring if anyone has
>>>> some
>>>> thoughts as to what we can do to make the compiler make be= tter choices
>>>> here. =A0There are two issues to overcome:
>>>>
>>>> Dropping the module name. =A0I'd love to give the comp= iler the hint that
>>>> Core.Std. could be dropped from the prefix in a context wh= ere that
>>>> module is
>>>> open. =A0This is what's done with the pervasives modul= e already, I
>>>> believe, so
>>>> it seems like it should be doable here.
>>>> Choosing shorter names. =A0This one seems harder, but ther= e are various
>>>> different possibilities for what type name to print out, a= nd a
>>>> reasonable
>>>> heuristic to use might be to pick the shortest one. =A0Par= t of the reason
>>>> these issues come up is our use of standardized interface = components
>>>> (that's
>>>> where the "stringable" type name comes from). = =A0I suspect this one will
>>>> be
>>>> hard to fix, sadly.
>>>>
>>>> Anyway, we'd be happy with any suggestions on how to i= mprove matters.
>>>>
>>>> y
>>>
>>>
>>> _______________________________________________
>>> Caml-list mailing list. Subscription management:
>>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/cam= l-list
>>> Archives: h= ttp://caml.inria.fr
>>> Beginner's list: http://groups.yahoo.com/group/ocaml_begi= nners
>>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>>>
>>>
>

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

--0015175ce094e35efb0475ae3841--