Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* right hand side of let rec
@ 1998-09-07 15:15 Laurent Chéno
  1998-09-08  7:08 ` Pierre Weis
  0 siblings, 1 reply; 2+ messages in thread
From: Laurent Chéno @ 1998-09-07 15:15 UTC (permalink / raw)
  To: Caml list

Sorry : poor-english version at the end.

Je ne comprends pas ce qui se passe avec le programme suivant :

(*****)
let ignore _ = () ;;

type 'a cycle = {	mutable val : 'a ;
					mutable pred : 'a cycle ;
					mutable succ : 'a cycle } ;;

let ajoute_au_cycle c x 	let p = c.pred
	and s = c.succ
	in
	let r =	{ val = x ; pred = p ; succ = c }
	in
	p.succ <- r ;
	c.pred <- r ;
	r ;;

let cycle_of_list l 	let rec r = { val = hd l ; succ = r ; pred = r }
	in
	do_list (function x -> ignore (ajoute_au_cycle r x)) (tl l) ;
	r ;;
(*****)

Caml me renvoie un message d'erreur :

#Entrée interactive:
>	let rec r = { val = hd l ; succ = r ; pred = r }
>	                    ^^^^
Ce genre d'expressions n'est pas autorisé comme membre droit d'un "let rec".


Bien sûr, j'ai contourné la difficulté en écrivant

let cycle_of_list l      let hd_l = hd l
     in
     let rec r = { val = hd_l ; succ = r ; pred = r }
     in
     do_list (function x -> ignore (ajoute_au_cycle r x)) (tl l) ;
     r ;;

Mais pourquoi Caml est-il si malheureux ?

Cordialement, Laurent Chéno

------- poor english

the later program causes an error : unauthorised expression in rhs of "let rec"
why ?





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

end of thread, other threads:[~1998-09-08  9:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-09-07 15:15 right hand side of let rec Laurent Chéno
1998-09-08  7:08 ` Pierre Weis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox