From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 3916D7EE51 for ; Sat, 13 Apr 2013 18:07:24 +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.48; 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.48 as permitted sender) identity=mailfrom; client-ip=74.125.83.48; 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-f48.google.com) identity=helo; client-ip=74.125.83.48; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="anthony.tavener@gmail.com"; x-sender="postmaster@mail-ee0-f48.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnMCAD6BaVFKfVMwk2dsb2JhbABQgzy5FwGINXwIFg4BAQEBBwsLCRQEJIIfAQEEAScZARsdAQMBCwYFCw0uIQEBEQEFARwGEwiHeQEDCQYMnRKML4J7hBUKGScNWYh+AQUMjDiCUweDQQOJBYwdgWOBIYpUgzoWKYRNHQ X-IPAS-Result: AnMCAD6BaVFKfVMwk2dsb2JhbABQgzy5FwGINXwIFg4BAQEBBwsLCRQEJIIfAQEEAScZARsdAQMBCwYFCw0uIQEBEQEFARwGEwiHeQEDCQYMnRKML4J7hBUKGScNWYh+AQUMjDiCUweDQQOJBYwdgWOBIYpUgzoWKYRNHQ X-IronPort-AV: E=Sophos;i="4.87,468,1363129200"; d="scan'208";a="13125761" Received: from mail-ee0-f48.google.com ([74.125.83.48]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 13 Apr 2013 18:07:23 +0200 Received: by mail-ee0-f48.google.com with SMTP id b15so1694669eek.21 for ; Sat, 13 Apr 2013 09:07:23 -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=QEGnb1ef4UaND6kk6M0R3GArfW5UpMLTWbnK5gldYRA=; b=AKrJWFKbZwIdKHa0tvhwDDyanIRfMet0v/h6CFyOp15CBfOetau1TqqGkHY253FAj2 nWW/TzqGqbb27Z68Esq/yTu+oT5v3jb23Qfnu6/eSeDcyhMQ/CXUcoJdtjFuixQL9U/3 JPdYE0LOiO06g05lCtiKXp49QCr3NEkwfpGoKwWJQTc0cuZhihnsphb6/Kko+hY6RcqY 9Sw4XTU/8g8HiQRdSBRYcr5xoGcOlAbv/x8/g3976B5KV/np909XGcOpinJH1iQRwIH+ n19X7lkxdOLWtU8t5mayj3X7i8tZQtqIsQBuOq6zcoXc39XOOrMNk/5lCTRYVUMge37X rJEw== MIME-Version: 1.0 X-Received: by 10.14.110.198 with SMTP id u46mr40745743eeg.41.1365869243053; Sat, 13 Apr 2013 09:07:23 -0700 (PDT) Received: by 10.14.7.4 with HTTP; Sat, 13 Apr 2013 09:07:22 -0700 (PDT) In-Reply-To: References: Date: Sat, 13 Apr 2013 10:07:22 -0600 Message-ID: From: Anthony Tavener To: Gabriel Scherer Cc: Kakadu , "caml-list@inria.fr" Content-Type: multipart/alternative; boundary=089e0158c2260ae60104da40377e Subject: Re: [Caml-list] Types look compatible, but they aren't? --089e0158c2260ae60104da40377e Content-Type: text/plain; charset=ISO-8859-1 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 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 > >> > >> > > > --089e0158c2260ae60104da40377e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Ohhh... that is interesting. (TL;DR: problem solved, and i= t was from inappropriate Oo.id use.)

Modifier.atta= ch is actually implemented as a function of one argument which does some st= uff,
returning a function of two arguments, to avoid redundant lookup= s in the case of multiple "attach"
to the same &q= uot;id".

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

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

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

As I wrote this I had an idea and fou= nd the problem:

=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, an= d 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

=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
> <anthony.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
>>
>>
>

--089e0158c2260ae60104da40377e--