From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id C829C7EE51 for ; Sat, 13 Apr 2013 18:15:27 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of anthony.tavener@gmail.com) identity=pra; client-ip=74.125.83.50; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="anthony.tavener@gmail.com"; x-sender="anthony.tavener@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of anthony.tavener@gmail.com designates 74.125.83.50 as permitted sender) identity=mailfrom; client-ip=74.125.83.50; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="anthony.tavener@gmail.com"; x-sender="anthony.tavener@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ee0-f50.google.com) identity=helo; client-ip=74.125.83.50; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="anthony.tavener@gmail.com"; x-sender="postmaster@mail-ee0-f50.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnMCAJGDaVFKfVMyjWdsb2JhbABQgzy5FwGINXwIFg4BAQEBBwsLCRIGJIIfAQEEAScZARsdAQMBCwYFCw0uIQEBEQEFARwGE4gBAQMJBgydD4wvgnuEFQoZJw1ZiH4BBQyMOIJTB4NBA4kFjB2BY4EhilSDOhYphE0d X-IPAS-Result: AnMCAJGDaVFKfVMyjWdsb2JhbABQgzy5FwGINXwIFg4BAQEBBwsLCRIGJIIfAQEEAScZARsdAQMBCwYFCw0uIQEBEQEFARwGE4gBAQMJBgydD4wvgnuEFQoZJw1ZiH4BBQyMOIJTB4NBA4kFjB2BY4EhilSDOhYphE0d X-IronPort-AV: E=Sophos;i="4.87,468,1363129200"; d="scan'208";a="13126523" Received: from mail-ee0-f50.google.com ([74.125.83.50]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 13 Apr 2013 18:15:27 +0200 Received: by mail-ee0-f50.google.com with SMTP id e53so1693117eek.37 for ; Sat, 13 Apr 2013 09:15:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=FwGuC928WKO9wMRWdg9WR1XKCoqZvwzpBCUjIndsSy8=; b=ubNAjng3DVGoAiciLgWG3eJbo4pIDeACkPSBQV/x63StkO1ci1aXUAuZ/bKbLyRc0B kMLgvBughbY3IDZitjdORWxeowtqfzk15E7/Ck4OY9XjFeBrVrJNzS25O4564Lu5q15C 1ZPRbcfa7kgValkPfe7V8ejx1lW3BDnZsKJPJT7swvXNl+oXBKfv6bMddFMAw/y8t8Yi MQcYdTgBYezEQg5V+lfPH31jBzQPS5Hk8jeiveXLLED77nNB3OsGwJPnrQkDGoyLQuzN HunumZz5btlvp/4NOzfBYGeMb5FAxskZoSUIdHMxsR7ZB4xhYAh1YduvSHKsN9I/BtdC 5bsg== MIME-Version: 1.0 X-Received: by 10.15.32.142 with SMTP id a14mr41359097eev.22.1365869726695; Sat, 13 Apr 2013 09:15:26 -0700 (PDT) Received: by 10.14.7.4 with HTTP; Sat, 13 Apr 2013 09:15:26 -0700 (PDT) In-Reply-To: References: Date: Sat, 13 Apr 2013 10:15:26 -0600 Message-ID: From: Anthony Tavener To: Gabriel Scherer Cc: Kakadu , "caml-list@inria.fr" Content-Type: multipart/alternative; boundary=089e01635210deb5ab04da4053b2 Subject: Re: [Caml-list] Types look compatible, but they aren't? --089e01635210deb5ab04da4053b2 Content-Type: text/plain; charset=ISO-8859-1 I forgot to note, that the interesting thing was how the type inferred for Modifier.attach when it had one argument applied did not show the < _.. > monomorphic object constraint. Modifier.attach is actually a: fun id -> (key -> fn -> deleter), rather than a straightforward three-argument function. Once the (key -> fn -> deleter) function would come into play, the "object" was revealed. On Sat, Apr 13, 2013 at 10:07 AM, Anthony Tavener wrote: > Ohhh... that is interesting. (TL;DR: problem solved, and it was from > inappropriate Oo.id use.) > > Modifier.attach is actually implemented as a function of one argument > which does some stuff, > returning a function of two arguments, to avoid redundant lookups in the > case of multiple "attach" > to the same "id". > > When I remove the let m = ... and just inline "Modifer.attach id ..." the > type of Modifier.attach changes to: > > Db.key -> int * (((< _.. > as 'a) list -> exn) * (exn -> 'a list) -> 'a > -> Modifier.deleter > > So, 'a becomes: (< _.. > as 'a) -- I get some monomorphic... object? > > As I wrote this I had an idea and found the problem: > > ... > (* return (tbl -> unit) function which deletes this specific function *) > let del_id = Oo.id fn in > (fun tbl -> > let lst = List.filter (fun e -> Oo.id e <> del_id) (fn_list tbl) in > Hashtbl.replace tbl tag (inj lst)) > > > Here, "fn" is the provided function, and I want an easy way to remove such > functions uniquely from the > mess of Hashtbl, universal embedding, and list. I tried a trick I once > read Alain suggest for getting a > unique id using the object module... and I guess that brought in this <..> > thing I was unfamiliar with. :) > Instead of Oo.id I'm using Hashtbl.hash now, which is normally what I'd > do... not sure why I > half-remembered some trick with Oo.id. > > Thank-you for looking at this, both of you. It helped me dig in the right > direction! > > > On Sat, Apr 13, 2013 at 1:33 AM, Gabriel Scherer < > gabriel.scherer@gmail.com> wrote: > >> This looks like a value restriction issue with >> >> let m = Modifier.attach id >> >> "A function obtained through partial application is not polymorphic >> enough" >> http://caml.inria.fr/resources/doc/faq/core.en.html#eta-expansion >> >> If this is indeed the source of your error, you can regain >> type-checking by using instead >> >> let m total = Modifier.attach id total >> >> Note that this may change the semantics of your code if >> (Modifier.attach id) does a side-effect before getting its next >> parameter: if would have been effected only once with your previous >> definition, and will be effected at each call of 'm' with the new >> definition. >> >> On Sat, Apr 13, 2013 at 8:56 AM, Kakadu >> wrote: >> > Maybe function type (int * int -> int * int) is incompatible with object >> > type <..>? >> > >> > Kakadu >> > >> > >> > On Sat, Apr 13, 2013 at 10:50 AM, Anthony Tavener >> > wrote: >> >> >> >> File "virtue.ml", line 462, characters 12-24: >> >> Error: This expression has type >> >> int * ((int * int -> int * int) list -> exn) * >> >> (exn -> (int * int -> int * int) list) >> >> but an expression was expected of type >> >> int * ((< .. > as 'a) list -> exn) * (exn -> 'a list) >> >> >> >> The code in question: >> >> >> >> (fun id -> >> >> let m = Modifier.attach id in >> >> [ m Cast.total'k (fun (v,b) -> (v, max 1 (b-3))) (* <-- line >> 462 >> >> *) >> >> ; m Lab.total'k (fun (v,b) -> (v, max 1 (b-3))) ]) >> >> >> >> For reference, the signature of Modifier.attach: >> >> Db.key -> int * ('a list -> exn) * (exn -> 'a list) -> 'a -> >> >> Modifier.deleter >> >> >> >> OCaml version is 4.00.0 -- I know I should upgrade. Keep meaning to, I >> >> guess I will if I wake up and there's no helpful soul explaining what >> >> could >> >> be wrong here. :) >> >> >> >> Thank-you for any help. My eyes are starting to bug-out looking at >> this. >> >> >> >> -Tony >> >> >> >> >> > >> > > --089e01635210deb5ab04da4053b2 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I forgot to note, that the interesting thing was how the t= ype inferred for Modifier.attach when it had
one argument applied did n= ot show the < _.. > monomorphic object constraint. Modifier.attach is actually a: fun id -> (key -> fn -> deleter), rather than a str= aightforward three-argument function. Once
the (key -> f= n -> deleter) function would come into play, the "object" was = revealed.


O= n Sat, Apr 13, 2013 at 10:07 AM, Anthony Tavener <anthony.tavener@= gmail.com> wrote:
Ohhh... that is interesting= . (TL;DR: problem solved, and it was from inappropriate Oo.id use.)
Modifier.attach is actually implemented as a function of one argument = which does some stuff,
returning a function of two arguments, to avoid redundant lookups in t= he case of multiple "attach"
to the same "id"= .

When I remove the let m =3D ... and just inline = "Modifer.attach id ..." the type of Modifier.attach changes to:

=A0 Db.key -> int * (((< _.. > as 'a) list= -> exn) * (exn -> 'a list) -> 'a -> Modifier.deleter

So, 'a becomes: (< _.. > as 'a) -= - I get some monomorphic... object?

As I wrote this I had an idea and found the probl= em:

=A0 ...
=A0 (* return (tbl ->= ; unit) function which deletes this specific function *)
=A0 let del_id =3D Oo.id fn in
=A0 (fun tbl ->
<= div>=A0 =A0 let lst =3D List.filter (fun e -> Oo.id e <> del_id) (= fn_list tbl) in
=A0 =A0 Hashtbl.replace tbl tag (inj lst))
<= div>

Here, "fn" is the provided function, and I wa= nt an easy way to remove such functions uniquely from the
mess of= Hashtbl, universal embedding, and list. I tried a trick I once read Alain = suggest for getting a
unique id using the object module... and I guess that brought in this = <..> thing I was unfamiliar with. :)
Instead of Oo.id I'= ;m using Hashtbl.hash now, which is normally what I'd do... not sure wh= y I
half-remembered some trick with Oo.id.

Thank-= you for looking at this, both of you. It helped me dig in the right directi= on!


On Sat, Apr 13, 2013 at 1:33 AM, Gabriel Scherer= <gabriel.scherer@gmail.com> wrote:
This looks like a value restriction issue with

=A0 let m =3D Modifier.attach id

=A0 "A function obtained through partial application is not poly= morphic enough"
=A0 http://caml.inria.fr/resources/doc/faq/core.en.htm= l#eta-expansion

If this is indeed the source of your error, you can regain
type-checking by using instead

=A0 let m total =3D Modifier.attach id total

Note that this may change the semantics of your code if
(Modifier.attach id) does a side-effect before getting its next
parameter: if would have been effected only once with your previous
definition, and will be effected at each call of 'm' with the new definition.

On Sat, Apr 13, 2013 at 8:56 AM, Kakadu <kakadu.hafanana@gmail.com> wrote:
> Maybe function type (int * int -> int * int) is incompatible with o= bject
> type <..>?
>
> Kakadu
>
>
> On Sat, Apr 13, 2013 at 10:50 AM, Anthony Tavener
> <ant= hony.tavener@gmail.com> wrote:
>>
>> File "virtue.m= l", line 462, characters 12-24:
>> Error: This expression has type
>> =A0 =A0 =A0 =A0 =A0int * ((int * int -> int * int) list -> e= xn) *
>> =A0 =A0 =A0 =A0 =A0(exn -> (int * int -> int * int) list)
>> =A0 =A0 =A0 =A0but an expression was expected of type
>> =A0 =A0 =A0 =A0 =A0int * ((< .. > as 'a) list -> exn)= * (exn -> 'a list)
>>
>> The code in question:
>>
>> =A0 (fun id ->
>> =A0 =A0 let m =3D Modifier.attach id in
>> =A0 =A0 =A0 [ m Cast.total'k (fun (v,b) -> (v, max 1 (b-3))= ) =A0 =A0 (* <-- line 462
>> *)
>> =A0 =A0 =A0 ; m Lab.total'k (fun (v,b) -> (v, max 1 (b-3)))= ])
>>
>> For reference, the signature of Modifier.attach:
>> =A0 Db.key -> int * ('a list -> exn) * (exn -> 'a= list) -> 'a ->
>> Modifier.deleter
>>
>> OCaml version is 4.00.0 -- I know I should upgrade. Keep meaning t= o, I
>> guess I will if I wake up and there's no helpful soul explaini= ng what
>> could
>> be wrong here. :)
>>
>> Thank-you for any help. My eyes are starting to bug-out looking at= this.
>>
>> =A0-Tony
>>
>>
>


--089e01635210deb5ab04da4053b2--