caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Florent Monnier <fmonnier@linux-nantes.fr.eu.org>
To: caml-list@yquem.inria.fr
Cc: Dawid Toton <d0@wp.pl>
Subject: Re: [Caml-list] Quantifier in the type
Date: Fri, 17 Oct 2008 01:06:15 +0200	[thread overview]
Message-ID: <200810170106.15327.fmonnier@linux-nantes.fr.eu.org> (raw)
In-Reply-To: <48F60638.6040101@uj.edu.pl>

Yes you are right my first answer was totally out of scope,
I will try to make it forgive and forget with this new one :)
Still take it with care while it seems you are far more knowledged than me
to answer to your own question ;-)

> Just an elementary question.
>
> I put 'a in the interface:
> val fu : 'a -> 'a
> and int in the implementation:
> let fu x = x + 1
>
> So I have universal quantification: for any type 'a function fu can
> consume the argument. So my implementation doesn't comply with that
> universal quatification. And the message I get is following:
>
> Values do not match: val fu : int -> int is not included in val fu : 'a
> -> 'a
>
> So the declaration of value in mli file is called simply a 'value'. Is
> it intentional?

in the same way, in the mli, it is not a "declaration of value" but "a 
declaration of the type of a value" :p

> I thought that value and it's declaration are separate notions?

doen't this declaration define a value?
Anyway doesn't the declaration and the value have the same type? (which do not 
match, and this is the real important piece, it do not match!)

Well if the error message was made this way, maybe it was more for clarity and 
simplicity, more than to be fully accurate to the theory.
Maybe it should rather say "the type of the implementation of the value does 
not match the type declared for this same value in the implementation"
but it's shorter to just say "values do not match"

> My reading of " val fu : 'a -> 'a " is:
>  some partiular value vvv that belongs to set of values that satisfy
> "forall 'a : (vvv can be used with ('a -> 'a) type)"

My reading of " val fu : 'a -> 'a " is that, as this 'a thing first appears in 
the ocaml manual which refers to it with "any type" or "arbitrary type" so 
"fu takes any type and returns this same arbitrary type"

Sorry for the joke, more serious attempts below

> But if I write
> let (bar : 'a -> 'a ) = (fun x -> x + 1)
> I create a value that belongs to set "exists 'a : (vvv can be used with
> ('a -> 'a) type)"
> So it's the other quantifier.

would this be a clue about the Gral you're looking for?

# let bar = ref (None : ('a -> 'a) option) ;;
val bar : ('_a -> '_a) option ref = {contents = None}
# bar := Some (fun x -> x + 1) ;;
- : unit = ()
# !bar ;;
- : (int -> int) option = Some <fun>

But:
# let (bar : '_a -> '_a) = (fun x -> x + 1) ;;
The type variable name '_a is not allowed in programs

is disallowed


> >> I think that the quantifier has to be part of type, since a type is set
> >> of values (and the quantifier plays important role when describing some
> >> of such sets).
> >> So my question is: since we see the same string " 'a -> 'a " that refers
> >> to different types in different contexts, what are the rules? How is
> >> type definition in OCaml translated to a type?
> >
> > type definition in OCaml are translated to actual types by inference.
> > (fun x -> x + 1) will be easily infered to (int -> int)
>
> My question was what are the rules for putting universal and
> existential quantifers into types. So we have some type definition:
> 'a -> ('b -> 'c)
> How is it translated to a type?
>
> I have an idea that this piece of code can sometimes be not a type
> definition, but rather part of type equation.
> Let's take my previous example:
> let (bar : 'a -> 'a ) = ...
>
> This " 'a -> 'a " whould not define any type (so the problem of
> quantifiers would be irrelevant here), but RHS of some type equation.
> Still I'm not sure about what does this RHS contais (precisely).

Is this example an illustration of what you mean ?

# let id v = v ;;
val id : 'a -> 'a = <fun>

# Scanf.sscanf "34" "%d" id ;;
- : int = 34

# Scanf.sscanf "4578.218" "%f" id ;;
- : float = 4578.218


and related to the quantifier kind, maybe noticing this will interest you:

# Scanf.sscanf ;;
- : string -> ('a, 'b, 'c, 'd) Scanf.scanner = <fun>

# Scanf.sscanf "34" ;;
- : ('_a, '_b, '_c, '_d) Scanf.scanner = <fun>

and finally, as you told, the complementary part of the 'a -> 'a:

# Scanf.sscanf "34" "%d" ;;
- : (int -> '_a) -> '_a = <fun>


> So: was I wrong thinking that existnetial quantifier is involved in this
> example?

as far as I understand now no, you was right on this point,
but you should have understood that you are more knowledged than me about this 
subject. I'm far from a guru and while there are many talented ones arround, I 
don't know why you didn't get an anwser from one of them, maybe because we 
don't really see what is the real problem behind your question?

-- 


      parent reply	other threads:[~2008-10-16 23:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-15 15:03 Dawid Toton
2008-10-15 18:18 ` [Caml-list] " Florent Monnier
2008-10-16 15:33   ` Dawid Toton
2008-10-17  8:11     ` Tiphaine Turpin
2008-10-17 11:40       ` Dawid Toton
2008-10-16 23:06 ` Florent Monnier [this message]

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=200810170106.15327.fmonnier@linux-nantes.fr.eu.org \
    --to=fmonnier@linux-nantes.fr.eu.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=d0@wp.pl \
    /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).