caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: rixed@happyleptic.org
To: caml-list@inria.fr
Subject: [Caml-list] Strange behavior from type inference after functor application
Date: Thu, 31 May 2012 22:05:55 +0200	[thread overview]
Message-ID: <20120531200555.GA30956@securactive.lan> (raw)

Given these definitions:

-- v1 --

module type TYPE = sig type t end

module Combi (S1 : TYPE) (S2 : TYPE) :
    TYPE with type t = S1.t * S2.t =
struct
    type t = S1.t * S2.t
end

module TypeWithConf (Conf : sig val v : int end) :
	TYPE =
struct
    type t = unit
end

module S = struct type t = unit end

module C = Combi (S) (TypeWithConf (struct let v = 1 end))

let f (x : C.t) = fst x

-----

Here, the compiler fails to infer that C.t is indeed the product of two types
(as stated in the Combi signature), and complains that:

Error: This expression has type C.t but an expression was expected of type 'a * 'b
(pointing at the argument of fst)

There is two ways to satisfies it:

- either, state that the type of TypeWithConf is 'TYPE with type t = unit'
  instead of merely 'TYPE'

- or, more surprisingly, to define the Conf structure as in:

-- v2 --
(* ... *)

module Conf = struct let v = 1 end
module C = Combi (S) (TypeWithConf (Conf))

(* ... *)
-----

Can someone help me find an explanation to this behavior?



             reply	other threads:[~2012-05-31 20:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-31 20:05 rixed [this message]
2012-05-31 20:23 ` Gabriel Scherer
2012-05-31 21:22   ` rixed
2012-05-31 22:36     ` Andreas Rossberg

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=20120531200555.GA30956@securactive.lan \
    --to=rixed@happyleptic.org \
    --cc=caml-list@inria.fr \
    /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).