caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Philippe Veber <philippe.veber@gmail.com>
To: Guillaume Yziquel <guillaume.yziquel@citycable.ch>
Cc: Goswin von Brederlow <goswin-v-b@web.de>, caml-list@inria.fr
Subject: Re: [Caml-list] Odd failure to infer types
Date: Sat, 3 Sep 2011 13:35:22 +0200	[thread overview]
Message-ID: <CAOOOohT0v8zrEE6TbzL9RXn5_-A3KHBsZUT3aL+gZHCGsYuWEQ@mail.gmail.com> (raw)
In-Reply-To: <20110903103653.GX15100@localhost>

[-- Attachment #1: Type: text/plain, Size: 3053 bytes --]

Hi, I'm really no typing expert and have not looked much into your code, so
sorry in advance if what I say is irrelevant. Christophe got it right I
think : I'd say that an array value cannot be polymorphic because it is
mutable. I've quickly searched the web and found that

http://mirror.ocamlcore.org/caml.inria.fr/pub/ml-archives/caml-list/2001/12/0dccd30f4582e551a674562e3ddcc03c.en.html

Quoting François Pottier:
"Any polymorphic, mutable structure is unsound and rightly rejected. A
monomorphic, mutable structure that contains polymorphic data is sound, but
cannot be expressed in ML's type system where universal quantification must
be prenex."

So it seems to me that whatever the way you try to achieve it, you simply
can't define a value state of type

val states : ('a list * (char * int * int) array * string) list array

(implicitely for all 'a). If the compiler is right, you'll always end up
with a weak type variable somewhere.

my 2 cent,

ph.


2011/9/3 Guillaume Yziquel <guillaume.yziquel@citycable.ch>

> Le Saturday 03 Sep 2011 à 11:53:30 (+0200), Goswin von Brederlow a écrit :
> > Hi,
> >
> > I'm implementing a solver for the game Atomix. If you don't know it then
> > don't worry. It isn't relevant.
> >
> > I split things up into submodules and now one of the submodules does not
> > infere the right types:
> >
> > File "Atomix.ml", line 168, characters 11-876:
> > Error: The type of this module,
> >        sig
> >          type dir = NORTH | SOUTH | WEST | EAST
> >          val max_moves : int
> >          val cache : (string, unit) Hashtbl.t
> >          val states :
> >            ('_a list * (char * int * int) array * string) list array
> >          val string_of_dir : dir -> string
> >          val print :
> >            (int * int * dir) list * (char * int * int) array * string ->
> unit
> >          val num_states : int
> >        end, contains type variables that cannot be generalized
> >
> > I believe this is wrong. In S.num_states the call to "print state"
> > fixates the type for state and the "states.(d) <- state::states.(d);"
> > should then fixate the missing '_a in the type for states.
> >
> > Anyone know why?
>
> It also seems quite wrong to me. You should perhaps file a bug into
> Mantis if no typing expert answers.
>
> Did you try adding type annotations one at a time near the call to print
> and the states.(d) assignment in your anonymous List.fold-ing function?
> To check precisely what the type inferencer gets right and what it gets
> wrong?
>
> I'd be curious to know whether annotating state in "states.(d) <-
> state::states.(d)" solves your problem. Since it's here that the '_a in
> the type of states should be fixated.
>
> --
>      Guillaume Yziquel
>
>
> --
> 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
>
>

[-- Attachment #2: Type: text/html, Size: 4126 bytes --]

  reply	other threads:[~2011-09-03 11:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-03  9:53 Goswin von Brederlow
2011-09-03 10:31 ` Christophe Papazian
2011-09-03 11:42   ` Guillaume Yziquel
2011-09-03 10:36 ` Guillaume Yziquel
2011-09-03 11:35   ` Philippe Veber [this message]
2011-09-03 11:46     ` Guillaume Yziquel
2011-09-03 12:15       ` Gabriel Scherer
2011-09-03 12:50         ` Guillaume Yziquel
2011-09-17 12:08         ` Goswin von Brederlow
2011-09-18  7:26           ` Gabriel Scherer

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=CAOOOohT0v8zrEE6TbzL9RXn5_-A3KHBsZUT3aL+gZHCGsYuWEQ@mail.gmail.com \
    --to=philippe.veber@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    --cc=guillaume.yziquel@citycable.ch \
    /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).