caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: Diego-Olivier.FERNANDEZ-PONS@cicrp.jussieu.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Simuler les vues avec des variantes polymorphes
Date: Fri, 16 Aug 2002 14:16:10 +0900	[thread overview]
Message-ID: <20020816141610D.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <Pine.A32.3.95.1020814103006.46622E-100000@ibm1.cicrp.jussieu.fr>

From: Diego Olivier Fernandez Pons <Diego-Olivier.FERNANDEZ-PONS@cicrp.jussieu.fr>
> type 'a heapView =
>   [ `Empty
>   | `Single of 'a * int
>   | `Link of 'a prioritySQ * 'a prioritySQ ]
[...]
> Seulement je ne peux par faire ceci
> 
> let insert x p = function
>   | `Empty -> ...
>   | `Single _ -> ...
>   | `Link _ -> ...
>   | other -> insert x p (to_heap_view other)
> 
> car le typeur n'accepte pas le mélange des types (je peux toujours
> mettre tous les constructeurs dans un seul type il est vrai mais ce
> n'est pas très propre) 

Je ne suis pas sur de tout comprendre, mais si le type de
to_heap_view est : 'a otherView -> 'a heapView
et si otherView est aussi un type de variant polymorphe, alors on peut
deja ecrire

    | #otherView as other -> insert x p (to_heap_view other)

Est-ce le comportement desire'?
Attention, si ton let ci-dessus est en fait un let rec, il faut
peut-etre ecrire:
    (to_heap_view other : ['a heapView] :> [> 'a heapView])
pour eviter d'unifier le resultat de to_heap_view a` l'entree de
insert.

> Est-il possible de concevoir des variantes polymorphes où le typeur
> accepterait des unions de types ? (en ce sens qu'au lieu de typer une
> fonction par les générateurs i.e. "tout type contenant Empty" ... il
> la type par union de tous les types déclarés qui contiennent Empty)

Et quid des types pas encore declares?
L'idee des variants polymorphes est de se debarasser des declarations
prealables.
Mais on peut toujours ecrire des declarations a` posteriori:

   type 'a anyView = ['a heapView | 'a otherView]

---------------------------------------------------------------------------
Jacques Garrigue      Kyoto University     garrigue at kurims.kyoto-u.ac.jp
		<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2002-08-16  5:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-14  8:37 Diego Olivier Fernandez Pons
2002-08-16  5:16 ` Jacques Garrigue [this message]
2002-08-21  8:37   ` Diego Olivier Fernandez Pons

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=20020816141610D.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=Diego-Olivier.FERNANDEZ-PONS@cicrp.jussieu.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).