From: Tyng-Ruey Chuang <trc@iis.sinica.edu.tw>
To: caml-list@inria.fr
Cc: trc@iis.sinica.edu.tw (Tyng-Ruey Chuang),
Jean-Christophe.Filliatre@lri.fr (Jean-Christophe Filliatre)
Subject: Re: [Caml-list] Weird types
Date: Mon, 18 Jun 2001 16:04:32 +0800 (CST) [thread overview]
Message-ID: <200106180804.QAA18021@iota.iis.sinica.edu.tw> (raw)
In-Reply-To: <15149.43599.979056.554953@pc803> from "Jean-Christophe Filliatre" at Jun 18, 2001 09:14:23 AM
Jean-Christophe FILLIATRE wrote:
> Actually, there is a type-able way of writing this function, which
> consists in duplicating it into two functions, like this:
>
> ======================================================================
> type ('a,'b,'c) t =
> | A of 'a * 'b * 'c
> | B of ('b, 'a, 'c) t
>
> let rec gamma = function
> | A _ -> 0
> | B x -> 1 + gamma' x
>
> and gamma' = function
> | A _ -> 0
> | B x -> 1 + gamma x
> ======================================================================
>
> which gives the expected types:
>
> ======================================================================
> val gamma : ('a, 'b, 'c) t -> int = <fun>
> val gamma' : ('a, 'b, 'c) t -> int = <fun>
> ======================================================================
Interesting! But then size of the duplicated code grows exponentially.
For example, for a 3-ary type constructor sigma
type ('a, 'b, 'c) sigma =
I of 'a * 'b * 'c
| T of ('b, 'a, 'c) sigma
| P of ('b, 'c, 'a) sigma
one need to define the 6 equivalent "length" functions gamma_xxx,
where xxx ranges from {abc, acb, bac, bca, cab, cba}, by
let rec gamma_abc s =
match s with
I _ -> 0
| T x -> 1 + gamma_bac x
| P x -> 1 + gamma_bca x
and gamma_acb s =
match s with
I _ -> 0
| T x -> 1 + gamma_cab x
| P x -> 1 + gamma_cba x
and gamma_bac s =
match s with
I _ -> 0
| T x -> 1 + gamma_abc x
| P x -> 1 + gamma_acb x
and gamma_bca s =
match s with
I _ -> 0
| T x -> 1 + gamma_cba x
| P x -> 1 + gamma_cab x
and gamma_cab s =
match s with
I _ -> 0
| T x -> 1 + gamma_acb x
| P x -> 1 + gamma_abc x
and gamma_cba s =
match s with
I _ -> 0
| T x -> 1 + gamma_bca x
| P x -> 1 + gamma_bac x
For the original definition of 7-ary sigma
type ('a,'b,'c,'d,'e,'f,'g) sigma =
I of 'a * 'b * 'c * 'd * 'e * 'f * 'g
| T of ('b,'a,'c,'d,'e,'f,'g) sigma
| P of ('b,'c,'d,'e,'f,'g,'a) sigma
one probably will need 7! = 5040 equivalent "length" functions
that are recursively defined among themselves!
I guess language-supported polymorphic recursions will help here.
However, I believe the general problem of typing polymorphic recursive
functions had been shown to be undecidable.
Tyng-Ruey Chuang
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
next prev parent reply other threads:[~2001-06-18 8:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-15 23:36 Berke Durak
2001-06-16 17:37 ` Tyng-Ruey Chuang
2001-06-18 7:14 ` Jean-Christophe Filliatre
2001-06-18 8:04 ` Tyng-Ruey Chuang [this message]
2001-06-18 12:15 ` Didier Remy
-- strict thread matches above, loose matches on Subject: below --
2001-06-15 19:35 Berke Durak
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=200106180804.QAA18021@iota.iis.sinica.edu.tw \
--to=trc@iis.sinica.edu.tw \
--cc=Jean-Christophe.Filliatre@lri.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;
as well as URLs for NNTP newsgroup(s).