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] Please help a newbie
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Francois Thomasset <Francois.Thomasset@i...>
Subject: Re: [Caml-list] Please help a newbie
Answer of another newbie: several things are wrong in your piece of code:

1/ 'a' is a char, and print_string works for strings, noted "a"

2/ your wys_die_lys has 2 arguments, as can be seen from the signature
val wys_die_lys : 'a -> string list -> unit list = <fun>
(the system deduced the string list type for the type of the second argument 
from the call to print_string in wys_dit). The 1st argument is named l, but 
you do pattern matching on the 2nd (which has no name). So wys_die_lys lys is 
another function:
wys_die_lys lys;;
- : string list -> unit list = <fun>
If you provide a list of chars as a 2nd argument to wys_die_lys it is rejected 
by the type checking:
wys_die_lys lys lys;;
This expression has type char list but is here used with type string list
Normal: see point 1/ above.

3/ Now if you give a string list as 2nd argument:
wys_die_lys lys ["a";"b";"c"];;
cba- : unit list = [(); (); ()]
The 1st argument lys is just passed around, and in fact ignored; wys_dit does 
its printing job and returns a unit to its caller, hence the list of units 
which is the result.

4/ Here is a definition which gets closer to what you expected:
let wys_dit woord = print_char woord;;
val wys_dit : char -> unit = <fun>
let rec wys_die_lys = function               
    [] -> ()                                   
    | h :: t -> begin wys_dit h ; wys_die_lys t end;;
val wys_die_lys : char list -> unit = <fun>
Now the units returned by calls to wys_dit are discared thanks to the sequence 
operator ` ; '. Note you have to pack the sequence between begin..end in an 
alternative, after the ` '-> '
# wys_die_lys lys;;                                     
abc- : unit = ()

Best Regards

					François Thomasset.
					INRIA (A3)

Tel: +33 (1) 39-63-54-75
Fax: +33 (1) 39-63-53-30 ou +33 (1) 39-63-59-95
Smail: INRIA, Rocquencourt, BP 105, 78153 Le Chesnay Cedex, France

Bug reports:  FAQ:
To unsubscribe, mail  Archives: