caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Francois Thomasset <Francois.Thomasset@inria.fr>
To: Johann Spies <jspies@maties.sun.ac.za>
Cc: ocaml mailing list <caml-list@inria.fr>
Subject: Re: [Caml-list] Please help a newbie
Date: Thu, 02 Aug 2001 15:01:16 +0200	[thread overview]
Message-ID: <200108021301.f72D1GT08449@ionie.inria.fr> (raw)
In-Reply-To: Message from Johann Spies <jspies@maties.sun.ac.za>  of "02 Aug 2001 13:42:13 -0000." <87lml2a896.fsf@#maties.sun.ac.za>

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
Email: Francois.Thomasset@inria.fr
Smail: INRIA, Rocquencourt, BP 105, 78153 Le Chesnay Cedex, France


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


  parent reply	other threads:[~2001-08-02 13:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-02 13:42 Johann Spies
2001-08-02 12:54 ` Frank Atanassow
2001-08-02 13:01 ` Francois Thomasset [this message]
2001-08-02 13:25   ` Francois Thomasset
2001-08-02 13:05 ` Sven
  -- strict thread matches above, loose matches on Subject: below --
2001-08-03 10:58 Johann Spies
2001-08-03 18:23 ` [Caml-list] Please help a newbie md5i
2001-08-05 21:37   ` John Max Skaller
2001-08-02 13:37 Dave Berry
2001-08-02 16:08 ` Brian Rogoff

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=200108021301.f72D1GT08449@ionie.inria.fr \
    --to=francois.thomasset@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=jspies@maties.sun.ac.za \
    /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).