List Info

Thread: "ocaml_beginners"::[] Re: ocaml for dummies




"ocaml_beginners"::[] Re: ocaml for dummies
country flaguser name
United States
2008-06-10 00:11:16

Sweet....looks good. Module String (link) is very cool. Much thanks,
dude! U re-motivated a new caml.

--- In ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com, Robert Fischer
<robert.fischer...> wrote:
&gt;
> 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
&gt;
> 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&quot; 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&quot; in the body, so you can pass in
different names. Check out the
> Pervasives module to see how to put "s&quot; and the string literals
together.
> http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html
&gt;
> ~~ Robert.
>
> William Lassiter wrote:
&gt; > # print_string "hello"; print_newline ();;
>; > hello
&gt; > - : 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
&gt; > # 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
&gt; > # 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
&gt; > # let greetings s = print_string Greetings, !;;
> > Syntax error
&gt; > # let greetings s = print_string (Greetings, )!;;
>; > Syntax error
&gt; > # let greetings s = print_string "Greetings, "!;;
> > Syntax error
&gt; > # let greetings s = print_string z
> > ''
> > ;;
> > Syntax error
&gt; > # let greetings s = print_endline "Greetings, "!;;
> > Syntax error
&gt; > # 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
&gt; > # let greetings s = print_string s "Greetings, "!;;
> > Syntax error
&gt; > # let greetings s = print_string -> "Greetings, "!;;
> > Syntax error
&gt; > #
> >
> > --- In ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com, Robert Fischer
> > <robert.fischer> wrote:
&gt; >> What have you been trying?
> >>
> >> ~~ Robert.
> >>
> >> William Lassiter wrote:
&gt; >>&gt; I'm not sure if the s parameter goes on the right with
&quot;Greetings, "!
> >>&gt; or what because every syntax I try produces a syntax error. This is
> >>&gt; my second week with this language and I haven't gotten the "Ah ha"
> > yet.
>; >>&gt; --- In ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com, Robert Fischer
> >>&gt; <robert.fischer> wrote:
&gt; >>&gt;> I'm not sure why you're lost, but it looks like all you're missing
> >>&gt; is prepending "Greetings, " and
> >>&gt;> appending "!&quot; to your string.
> >>&gt;>
&gt; >>&gt;> Where are you getting lost?
&gt; >>&gt;>
&gt; >>&gt;> ~~ Robert.
> >>&gt;>
&gt; >>&gt;> William Lassiter wrote:
&gt; >>&gt;>> I'm totally lost. I was given an assignment to write a function
> >>&gt;>> greetings that will print a greeting to the name given the
function;
>; >>&gt;>> the return value should be unit, and the greeting should be
followed
> >>&gt;>> by a single newline. Given:
&gt; >>&gt;>>
> >>&gt;>> # print_string "hello"; print_newline ();;
>; >>&gt;>> hello
&gt; >>&gt;>> - : unit = ()
> >>&gt;>> #let greetings s = ... ;;
> >>&gt;>> val greetings : string -> unit = <fun>;
> >>&gt;>> #greetings "Mark";;
> >>&gt;>> Greetings, Mark!
&gt; >>&gt;>> - : unit = ()
> >>&gt;>>
> >>&gt;>> The closest I've came was:
>; >>&gt;>>
> >>&gt;>> # let greetings s = print_string s;;
> >>&gt;>> val greetings : string -> unit = <fun>;
> >>&gt;>> # greetings "Mark";;
> >>&gt;>> Mark- : unit = ()
> >>&gt;>>
> >>&gt;>> Why am I so lost with OCaml? I learned Perl, C++, Java and they
>; >>&gt;>> seemed simple in the beginning but OCaml....
> >>&gt;>>
> >>&gt;>>
> >>&gt;
> >>&gt;
> >
> >
> >
>;

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )