Sweet....looks good. Module String (link) is very cool. Much thanks,
dude! U re-motivated a new caml.
--- In ocaml_beginners%40yahoogroups.com">ocaml_beginners
yahoogroups.com, Robert Fischer
<robert.fischer
...> wrote:
>
> Wow. That's probably the most thorough answer I've ever gotten to
that question.
>
> Okay, so you've got at least three going on here -- first of all,
you always want to use the form
> "let greetings s = " -- the whole minus sign thing is heading the
wrong direction.
>
> Second, just like in Java, C++, and Perl, things between
double-quotes are string literals. Things
>
> Finally, "let greetings s =" defines a function that takes a single
parameter. The body of the
> function is on the right side of the equals sign. You're going to
want to use the parameter in the
> body, because when you do
> # greetings "Mark";;
> the parameter "s" is going to take the value "Mark", and that's what
you want to print out.
>
> Your closest lead is this one:
> > # let greetings s = print_string "Greetings, Mark!";;
> > val greetings : 'a -> unit = <fun>
> > # greetings "Mark";;
> > Greetings, Mark!- : unit = ()
>
> All you're missing is using the "s" in the body, so you can pass in
different names. Check out the
> Pervasives module to see how to put "s" and the string literals
together.
> http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html
>
> ~~ Robert.
>
> William Lassiter wrote:
> > # print_string "hello"; print_newline ();;
> > hello
> > - : unit = ()
> > # let greetings s = print_string greetings;;
> > Unbound value greetings
> > # let greetings s = print_endline "Greetings";;
> > val greetings : 'a -> unit = <fun>
> > # let greetings s = print_string "Greetings";;
> > val greetings : 'a -> unit = <fun>
> > # greetings "Mark";;
> > Greetings- : unit = ()
> > # let greetings s - print_string "Greetings, Mark!";;
> > Syntax error
> > # let greetings s = print_string "Greetings, Mark!";;
> > val greetings : 'a -> unit = <fun>
> > # greetings "Mark";;
> > Greetings, Mark!- : unit = ()
> > # let greetings s = print_string ();;
> > This expression has type unit but is here used with type string
> > # let greetings s = print_string "Greetings, ";;
> > val greetings : 'a -> unit = <fun>
> > # let greetings s = print_string s;;
> > val greetings : string -> unit = <fun>
> > # greetings "Mark";;
> > Mark- : unit = ()
> > # let greetings s = print_string Greetings s;;
> > This function is applied to too many arguments, maybe you forgot a `;'
> > # let greetings s = print_endline "Greetings, ";;
> > val greetings : 'a -> unit = <fun>
> > # let greetings s = print_endline Greetings;;
> > Unbound constructor Greetings
> > # let greetings s = print_string "Greetings, "!;;
> > Syntax error
> > # let greetings s = print_string Greetings, !;;
> > Syntax error
> > # let greetings s = print_string (Greetings, )!;;
> > Syntax error
> > # let greetings s = print_string "Greetings, "!;;
> > Syntax error
> > # let greetings s = print_string z
> > ''
> > ;;
> > Syntax error
> > # let greetings s = print_endline "Greetings, "!;;
> > Syntax error
> > # let greetings s = print_endline "Greetings, "! s;;
> > This function is applied to too many arguments, maybe you forgot a `;'
> > # let greetings s = print_string "Greetings, "! s;;
> > This function is applied to too many arguments, maybe you forgot a `;'
> > # let greetings s = print_string "Greetings, "!;;
> > Syntax error
> > # let greetings s = print_string s "Greetings, "!;;
> > Syntax error
> > # let greetings s = print_string -> "Greetings, "!;;
> > Syntax error
> > #
> >
> > --- In ocaml_beginners%40yahoogroups.com">ocaml_beginners
yahoogroups.com, Robert Fischer
> > <robert.fischer
> wrote:
> >> What have you been trying?
> >>
> >> ~~ Robert.
> >>
> >> William Lassiter wrote:
> >>> I'm not sure if the s parameter goes on the right with
"Greetings, "!
> >>> or what because every syntax I try produces a syntax error. This is
> >>> my second week with this language and I haven't gotten the "Ah ha"
> > yet.
> >>> --- In ocaml_beginners%40yahoogroups.com">ocaml_beginners
yahoogroups.com, Robert Fischer
> >>> <robert.fischer
> wrote:
> >>>> I'm not sure why you're lost, but it looks like all you're missing
> >>> is prepending "Greetings, " and
> >>>> appending "!" to your string.
> >>>>
> >>>> Where are you getting lost?
> >>>>
> >>>> ~~ Robert.
> >>>>
> >>>> William Lassiter wrote:
> >>>>> I'm totally lost. I was given an assignment to write a function
> >>>>> greetings that will print a greeting to the name given the
function;
> >>>>> the return value should be unit, and the greeting should be
followed
> >>>>> by a single newline. Given:
> >>>>>
> >>>>> # print_string "hello"; print_newline ();;
> >>>>> hello
> >>>>> - : unit = ()
> >>>>> #let greetings s = ... ;;
> >>>>> val greetings : string -> unit = <fun>
> >>>>> #greetings "Mark";;
> >>>>> Greetings, Mark!
> >>>>> - : unit = ()
> >>>>>
> >>>>> The closest I've came was: