caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* is there a switch or cond-statement? nested functions?
@ 2008-09-03 17:08 circ ular
  2008-09-03 17:24 ` [Caml-list] " Christophe TROESTLER
  0 siblings, 1 reply; 3+ messages in thread
From: circ ular @ 2008-09-03 17:08 UTC (permalink / raw)
  To: caml-list

thanks, the type problem is solved. but is there a way to write nested
functions? so the powerf isn't exposed outwards...

and how can I rewrite the if statements in a case or cond way? pattern
mathcing is only on types right? cond a la scheme would be nice.

let rec powerf(n, pow, acc) =
    if pow > 0.0
	then powerf(n, pow -. 1., acc *. n)
	else if pow < 0.0
	    then 1. /. powerf(n, pow *. (-1.), acc)
	    else acc ;;
let power(n, pow) = powerf(n, pow, 1.);;



---------- Forwarded message ----------
From:  <Ephaeton@gmx.net>
Date: Wed, Sep 3, 2008 at 7:27 AM
Subject: Re: [Caml-list] is there a switch or cond-statement? + type-problem
To: circ ular <circularfunc@gmail.com>


On Wed, Sep 03, 2008 at 06:55:22AM +0200, circ ular wrote:
> thanks, not it compiles but I get this error instead:
> # powerx(5.0,2.0);;
> Characters 6-15:
>   powerx(5.0,2.0);;
>         ^^^^^^^^^
> This expression has type float * float but is here used with type
>   float * float * float
> #

The error message tells you: You called powerx with two float parameters,
but you need three float parameters. When loooking at the definition
you see that you forgot to give the argument for the accumulator. Try
calling i as powerx(5., 2., 1.) instead :)

With kind regards,

-Martin


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] is there a switch or cond-statement? nested functions?
  2008-09-03 17:08 is there a switch or cond-statement? nested functions? circ ular
@ 2008-09-03 17:24 ` Christophe TROESTLER
  2008-09-03 17:38   ` Daniel Bünzli
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe TROESTLER @ 2008-09-03 17:24 UTC (permalink / raw)
  To: circularfunc; +Cc: OCaml Mailing List

On Wed, 3 Sep 2008 19:08:33 +0200, circ ular wrote:
> 
> thanks, the type problem is solved. but is there a way to write nested
> functions? so the powerf isn't exposed outwards...
> 
> and how can I rewrite the if statements in a case or cond way? pattern
> mathcing is only on types right? cond a la scheme would be nice.
> (...)

May I suggest

1. You read http://www.ocaml-tutorial.org/ and at least chap 1-4 of
   http://caml.inria.fr/pub/docs/oreilly-book/html/index.html  That
   will clear up most of your questions.

2. You direct subsequent questions to the beginner's list
   http://groups.yahoo.com/group/ocaml_beginners where you will
   receive proper help for your concerns.

Thanks,
C.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] is there a switch or cond-statement? nested functions?
  2008-09-03 17:24 ` [Caml-list] " Christophe TROESTLER
@ 2008-09-03 17:38   ` Daniel Bünzli
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Bünzli @ 2008-09-03 17:38 UTC (permalink / raw)
  To: OCaml Mailing List


Le 3 sept. 08 à 19:24, Christophe TROESTLER a écrit :

> May I suggest

[...]

3. Have a look at the the programming guidelines [1]. In particular,  
this point [2] may show you a cond is not needed to make your code  
nice and readable.

Best,

Daniel

[1] http://caml.inria.fr/resources/doc/guides/guidelines.en.html
[2] http://caml.inria.fr/resources/doc/guides/guidelines.en.html#id2269347

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-09-03 17:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-03 17:08 is there a switch or cond-statement? nested functions? circ ular
2008-09-03 17:24 ` [Caml-list] " Christophe TROESTLER
2008-09-03 17:38   ` Daniel Bünzli

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).