caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Goswin von Brederlow <goswin-v-b@web.de>
Cc: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Error: In this definition, a type variable cannot be deduced from the type parameters.
Date: Mon, 7 Mar 2016 00:30:14 +0900	[thread overview]
Message-ID: <4C32FD84-31A8-4516-9DB1-93B4B0CF9DE2@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <20160306013332.GA27650@frosties>

2016/03/06 10:33, Goswin von Brederlow <goswin-v-b@web.de>:
> 
> Hi,
> 
> if I use the type aliases in the commented out lines then I get:
> 
>    Error: In this definition, a type variable cannot be deduced
>    from the type parameters.
> 
> To me the types sure do look alike and nothing is private or hidden my
> a signature. So what am I missing?
> 
> MfG
> 	Goswin

The problem is that you are using abstract types in separate modules.
As a result, the type system cannot recognize them as injective, and
gives the above error message.
You should either make it a datatype or a structural type:
  type +'a qObject' = Q of 'a
or
  type +'a qObject' = [`QObject' of 'a]

Jacques Garrigue

> -------------------------------------------------------------------------
> module Proxy = struct
>  type +'a t
> end
> 
> module QObject = struct
>  type +'a qObject'
>  type +'a t = 'a qObject' Proxy.t
> 
>  class ['a] qObject proxy = object
>    constraint 'a = 'b qObject' as 'a
>    method proxy : 'a Proxy.t = proxy
>  end
> end
> 
> module QWidget = struct
>  type +'a qWidget'
>  type +'a t = 'a qWidget' QObject.t
> 
>  external add : 'a qWidget' QObject.qObject' Proxy.t -> 'b qWidget' QObject.qObject' Proxy.t -> unit = "add"
>  (*
>    external add : 'a t -> 'b qWidget' QObject.t -> unit = "add"
>  *)
>  class ['a] qWidget proxy = object
>    constraint 'a = 'b qWidget' QObject.qObject' as 'a
>    inherit ['a] QObject.qObject proxy
>    method add : 'c 'd . ('d qWidget' QObject.qObject' #QObject.qObject as 'c) -> unit = fun w -> add proxy w#proxy
>  end
> end
> 
> module QButton = struct
>  type +'a qButton'
>  type +'a t = 'a qButton' QWidget.t
> 
>  external set : 'a qButton' QWidget.qWidget' QObject.qObject' Proxy.t -> 'b QWidget.qWidget' QObject.qObject' Proxy.t -> unit = "set"
>  (*
>    external set : 'a t -> 'b QWidget.t -> unit = "set"
>  *)
>  class ['a] qButton proxy = object
>    constraint 'a = 'b qButton' QWidget.qWidget' QObject.qObject' as 'a
>    inherit ['a] QWidget.qWidget proxy
>    method set : 'c 'd . ('c QWidget.qWidget' QObject.qObject' #QWidget.qWidget as 'd) -> unit = fun w -> set proxy w#proxy
>    method text = "button"
>  end
> end
> 
> let qObject_proxy : unit QObject.t = Obj.magic 0
> let qWidget_proxy : unit QWidget.t = Obj.magic 0
> let qButton_proxy : unit QButton.t = Obj.magic 0
> let qObject = new QObject.qObject qObject_proxy
> let qWidget = new QWidget.qWidget qWidget_proxy
> let qButton = new QButton.qButton qButton_proxy
> let () = qWidget#add qWidget
> let () = qWidget#add qButton
> let () = qButton#set qWidget
> let () = qButton#set qButton
> let () = qButton#add qWidget
> let () = qButton#add qButton
> 
> -- 
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs


  reply	other threads:[~2016-03-06 15:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-06  1:33 Goswin von Brederlow
2016-03-06 15:30 ` Jacques Garrigue [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-02-22 17:54 Goswin von Brederlow
2014-02-23  9:18 ` Jacques Garrigue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C32FD84-31A8-4516-9DB1-93B4B0CF9DE2@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).