caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: rixed@happyleptic.org
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Strange behavior from type inference after functor application
Date: Thu, 31 May 2012 22:23:13 +0200	[thread overview]
Message-ID: <CAPFanBFM6cqcutZUq9m=x6v-yEYT4LPGF1Zpv-Pp_WrXFfKQcw@mail.gmail.com> (raw)
In-Reply-To: <20120531200555.GA30956@securactive.lan>

The problem with
  module C = Combi (S) (TypeWithConf (struct let v = 1 end))
is that the resulting type has no "name": (struct let v = 1 end) can
not be part of a type path.

On the contrary, TypeWithConf(Conf) has a type t with name
TypeWithConf(Conf).t, so C.t can be equal to S.t *
TypeWithConf(Conf).t. There would be no such type as S.t *
TypeWIthConf(struct let v = 1 end).t.

The other fix, forcing TypeWithConf to return a signature with (t =
unit), makes the "naming problem" go away: whatever functor you pass
as a parameter (either a path such as "Conf" or a struct exrpession),
the resulting type is equal to "unit", you don't have to try to name
it from the way it was constructed.

On Thu, May 31, 2012 at 10:05 PM,  <rixed@happyleptic.org> wrote:
> 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?
>
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-31 20:05 rixed
2012-05-31 20:23 ` Gabriel Scherer [this message]
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='CAPFanBFM6cqcutZUq9m=x6v-yEYT4LPGF1Zpv-Pp_WrXFfKQcw@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=rixed@happyleptic.org \
    /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).