Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] actualize a string
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Hurt <bhurt@s...>
Subject: Re: [Caml-list] actualize a string
On Thu, 23 Oct 2003, Flavio Leonardo Cavalcanti de Moura wrote:

> 	I am trying to build a procedure such that some reductions are
> performed while a list (of redex) is not empty. The problem is that a
> new list is needed at each step otherwise it will loop for ever. The
> actual code is
> let normal exp =
>  let l = exp :: [] in
>  while (matchingApp exp [] []) <> [] do
>        exp := (appreduction exp (hd (matchingApp exp [] [])));
>        exp :: l done; l;;
> After the 'while' I would like to actualize the expression 'exp' with the
> string (appreduction exp (hd (matchingApp exp [] []))). The problem is
> that with := it does not work. How can I do that? I couldn't find anything
> in the ocaml manual.

I'm not 100% sure what you're trying to do here.  Applying a function to 
every member of a list is easy- look at List.iter and List.fold_left.  
fold_left is especially useful for "accumulating" a result over the list.

I think what you want to do is:

let normal exp = 
	let f l x = 
		match l with
			| [] -> assert false
			| h :: t -> (appreduction h x) :: t
	List.fold_left f [ exp ] (matchingApp exp [] [])

but I'm not sure.

Give me a clue: what are the types of matchingApp and appreduction?


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: