From: Eric HASSOLD <hassold@mad.unice.fr>
To: David Monniaux <David.Monniaux@ens-lyon.fr>
Cc: Caml-list <caml-list@inria.fr>
Subject: Re: bizarrerie du typage
Date: Mon, 13 Jan 1997 12:41:13 +0100 [thread overview]
Message-ID: <32DA1F59.41C67EA6@mad.unice.fr> (raw)
In-Reply-To: <Pine.GSO.3.95.970112201324.25242B-100000@brotteaux>
David Monniaux wrote:
>
> J'ai un exemple assez amusant de bizarreries du typage:
>
> Objective Caml version 1.01
>
> #let zero = fun x y -> y;;
> val zero : 'a -> 'b -> 'b = <fun>
> #let succ = fun n f x -> n f (f x);;
> val succ : (('a -> 'b) -> 'b -> 'c) -> ('a -> 'b) -> 'a -> 'c = <fun>
> #let un = succ zero;;
> val un : ('_a -> '_b) -> '_a -> '_b = <fun>
> #let deux = succ un;;
> val deux : ('_a -> '_a) -> '_a -> '_a = <fun>
> #deux (fun x -> x) 0;;
> - : int = 0
> #deux;;
> - : (int -> int) -> int -> int = <fun>
>
le symbole _ dans le type ('_a et non 'a) indique qu'il s'agit d'un type
statique qui doit cependant attendre le premier appel de la fonction
pour etre resolu et assigne definitivement (le type int dans ton
exemple).
Si tu veux preserver le polymorphisme des fonctions un et deux, declare
les arguments explicitement, c-a-d
let un = fun f x -> succ zero f x;;
val un : ('a -> 'b) -> 'a -> 'b = <fun>
let deux = fun f x -> succ un f x;;
val deux : ('a -> 'a) -> 'a -> 'a = <fun>
Alors, tu obtiens bien :
deux (fun x -> x) 0;;
- : int = 0
mais toujours
deux;;
- : ('a -> 'a) -> 'a -> 'a = <fun>
> "Si l'informatique marchait, cela se saurait."
Je trouve que ca se sait...
-----
Eric Hassold
Université de Nice - Sophia Antipolis
Laboratoire de Mathématiques
Parc Valrose
06108 Nice Cedex 02 - France
Téléphone : (33) 04 92 07 62 89
Email : hassold@mad.unice.fr
WWW : http://math.unice.fr/~hassold
prev parent reply other threads:[~1997-01-14 7:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-01-12 19:19 David Monniaux
1997-01-13 11:41 ` Eric HASSOLD [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=32DA1F59.41C67EA6@mad.unice.fr \
--to=hassold@mad.unice.fr \
--cc=David.Monniaux@ens-lyon.fr \
--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