caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] Not allowed as right-hand side of 'let rec'
@ 2002-08-09  8:48 Diego Olivier Fernandez Pons
  0 siblings, 0 replies; 4+ messages in thread
From: Diego Olivier Fernandez Pons @ 2002-08-09  8:48 UTC (permalink / raw)
  To: caml-list

    Bonjour,

Tom Hirschowitz a écrit :

> je comprends pas ce que le fait de prendre un type union change.

C'est que j'ai immédiatement pensé à mettre mon pointeur sur Nil
(comme on le ferait en C) puis l'affecter ensuite, seulement Caml ne
possédant pas de pointeur Nil, la première idée qui m'est venue en
tête fut de le simuler par un type Empty | List of ...

Au demeurant, la solution de Michel Quercia fait presque la même chose
en initialisant le tableau à [||] puis en le remplissant ensuite.

Enfin, j'avais cru lire dans un rapport de recherche que
l'introduction d'un type Nil était à l'étude. Qu'en est-il désormais ?

        Diego Olivier

-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Not allowed as right-hand side of 'let rec'
  2002-08-08 12:56 ` Michel Quercia
@ 2002-08-08 13:30   ` Alain Frisch
  0 siblings, 0 replies; 4+ messages in thread
From: Alain Frisch @ 2002-08-08 13:30 UTC (permalink / raw)
  To: Michel Quercia; +Cc: Caml list

On Thu, 8 Aug 2002, Michel Quercia wrote:

> > note : si l'on pouvait avoir un affichage un peu plus réduit pour les
> > enregistrements qui pointent sur eux-mêmes ?
>
> Vous pouvez écrire une fonction d'impression ad-hoc et signaler au
> toplevel de l'utiliser via la directive install_printer.

Ou alors patcher un peu la routine d'affichage générique du toplevel, pour
qu'elle se rende compte qu'il y a des boucles et affiche des choses du
genre:

let v1 = { bla = v1; blo = v2 } and v2 = (v1,v1) in (v1,v2)

J'avais envoyé un patch (sale) à caml-bugs pour accompagner un
feature-wish en ce sens, ça doit pouvoir se retrouver dans l'interface
web (sinon, si ça intéresse quelqu'un, je peux l'extraire de nouveau).

-- Alain

-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Not allowed as right-hand side of 'let rec'
  2002-08-08 12:08 Diego Olivier Fernandez Pons
@ 2002-08-08 12:56 ` Michel Quercia
  2002-08-08 13:30   ` Alain Frisch
  0 siblings, 1 reply; 4+ messages in thread
From: Michel Quercia @ 2002-08-08 12:56 UTC (permalink / raw)
  To: caml-list

Le Thu, 8 Aug 2002 14:08:58 +0200 (DST)
Diego Olivier Fernandez Pons
<Diego-Olivier.FERNANDEZ-PONS@cicrp.jussieu.fr> écrivit :

> Je suis entrain de coder des Skip Lists ...
> ...
> let rec single = function x ->
>   let h = Random.int max_height in
>   let rec s = { next = Array.make h s ; next = x }
> in (1, s)
> 
> Le compilateur répond : This kind of expression is not allowed as
> right-hand side of 'let rec'

Car s est défini en fonction de lui-même par un appel de fonction : s =
f(s) et le compilateur ne sait pas calculer automatiquement un point fixe
de f. Ceci devrait marcher :

let single = function x ->
  let h = Random.int max_height in
  let dummy = {next = [||]; content = x} in
  let s = { next = Array.make h dummy ; content = x } in
  Array.fill s.next 0 h s;
  (1, s)

> note : si l'on pouvait avoir un affichage un peu plus réduit pour les
> enregistrements qui pointent sur eux-mêmes ?

Vous pouvez écrire une fonction d'impression ad-hoc et signaler au
toplevel de l'utiliser via la directive install_printer.

Cordialement,
-- 
Michel Quercia
23 rue de Montchapet, 21000 Dijon
http://michel.quercia.free.fr (maths)
http://pauillac.inria.fr/~quercia (informatique)
mailto:michel.quercia@prepas.org
-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Caml-list] Not allowed as right-hand side of 'let rec'
@ 2002-08-08 12:08 Diego Olivier Fernandez Pons
  2002-08-08 12:56 ` Michel Quercia
  0 siblings, 1 reply; 4+ messages in thread
From: Diego Olivier Fernandez Pons @ 2002-08-08 12:08 UTC (permalink / raw)
  To: caml-list

    Bonjour,

Je suis entrain de coder des Skip Lists (William Pugh 1990, 1994) qui
est une structure de données populaire outre-Atlantique et consiste en
une liste circulaire chaînée dont tout élément de hauteur h pointe en
outre vers son 2^k successeur avec k < h (le tout à la sauce random
américaine)

M'inspirant des listes circulaires chaînées (Cousineau et Mauny,
Pottier) j'ai écrit :

type 'a cell = { next : 'a cell array ; content : 'a }
type 'a skipList = int * 'a cell

Random.self_init ();;
let max_height = 10;;

let rec single = function x ->
  let h = Random.int max_height in
  let rec s = { next = Array.make h s ; next = x }
in (1, s)

Le compilateur répond : This kind of expression is not allowed as
right-hand side of 'let rec', me forçant à me rabattre sur un type
union

 type 'a cell = E | C of 'a cell array * 'a

Pourquoi son comportement est-il différent du cas des listes
circulaires simplement chaînées ? 

 type 'a cell = { next : 'a cell ; content ; 'a }

        Diego Olivier

note : si l'on pouvait avoir un affichage un peu plus réduit pour les
enregistrements qui pointent sur eux-mêmes ?

-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-08-09  8:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-09  8:48 [Caml-list] Not allowed as right-hand side of 'let rec' Diego Olivier Fernandez Pons
  -- strict thread matches above, loose matches on Subject: below --
2002-08-08 12:08 Diego Olivier Fernandez Pons
2002-08-08 12:56 ` Michel Quercia
2002-08-08 13:30   ` Alain Frisch

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).