caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] This expression is not a function, it cannot be applied
@ 2001-09-09 11:11 Johann Spies
  2001-09-09 11:25 ` Remi VANICAT
  2001-09-09 11:38 ` Mike Leary
  0 siblings, 2 replies; 4+ messages in thread
From: Johann Spies @ 2001-09-09 11:11 UTC (permalink / raw)
  To: ocaml

Hello,

I can not see what is wrong in the following code.  Why do I get the
following error:
------------------------------------
# let j koers = koers /. 100.0/. 12.0;;

val j : float -> float = <fun>
#   let n jare = jare *. 12.0;;

val n : float -> float = <fun>
#   let paaiement j n bedrag = 
  (bedrag *. j /. (1.0 -. exp (-.n *. log (1.0 +. j))));;
  val paaiement : float -> float -> float -> float = <fun>
# let druk_ry m h r a = Printf.printf "
               %02f\t%04.02f\t%04.02f\t%04.02f\n" (m h r a);;
  val druk_ry :
  ('a -> 'b -> 'c -> float) ->
  'a -> 'b -> 'c -> float -> float -> float -> unit = <fun>
# let rec druk_tabel hoofsom pmnt j n maand  = match (maand, hoofsom) with
   (n, 0.) -> ()
  |(0., _) -> print_string "ongeldige tydperk\n"; print_newline()
  | (_, _) ->  if maand == 1. then Printf.printf "Maand\tBedrag\tRente\tAfbetaal";
               let rente = hoofsom *. j in
                 let afbetaal = pmnt -. rente in 
                   let nuwe_hoofsom = hoofsom -. afbetaal in
                      druk_ry (maand hoofsom rente afbetaal);
		        druk_tabel nuwe_hoofsom pmnt j n maand+1;;

                Characters 424-429:
This expression is not a function, it cannot be applied
----------------------------
The culprit is "maand " in the second last row (druk_ry (maand...))

Why can it not be applied?

Johann
-- 
J.H. Spies - Tel. 082 782 0336 / 021-808 4036(w)  
             Posbus 4668, Tygervallei 7536
     "Submit yourselves therefore to God. Resist the devil, 
      and he will flee from you."        James 4:7 
-------------------
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


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

* Re: [Caml-list] This expression is not a function, it cannot be applied
  2001-09-09 11:11 [Caml-list] This expression is not a function, it cannot be applied Johann Spies
@ 2001-09-09 11:25 ` Remi VANICAT
  2001-09-09 11:38 ` Mike Leary
  1 sibling, 0 replies; 4+ messages in thread
From: Remi VANICAT @ 2001-09-09 11:25 UTC (permalink / raw)
  To: caml-list

Johann Spies <jhspies@adept.co.za> writes:

> Hello,

> # let rec druk_tabel hoofsom pmnt j n maand  = match (maand, hoofsom) with
>    (n, 0.) -> ()
>   |(0., _) -> print_string "ongeldige tydperk\n"; print_newline()
>   | (_, _) ->  if maand == 1. then Printf.printf "Maand\tBedrag\tRente\tAfbetaal";
>                let rente = hoofsom *. j in
>                  let afbetaal = pmnt -. rente in 
>                    let nuwe_hoofsom = hoofsom -. afbetaal in
>                       druk_ry (maand hoofsom rente afbetaal);
> 		        druk_tabel nuwe_hoofsom pmnt j n maand+1;;
> 
>                 Characters 424-429:
> This expression is not a function, it cannot be applied
> ----------------------------
> The culprit is "maand " in the second last row (druk_ry (maand...))
> 
> Why can it not be applied?

you do a
match (maand, hoofsom) with
...
| (0.,_) ->

so the compiler thinks that maand is a float, not a function.
and then you do a 
(maand hoofsom rente afbetaal)
which mean: apply the function maand to the argument hoofsom rente and
afbetaal, so it is an error since maand is not a function.


-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
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


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

* Re: [Caml-list] This expression is not a function, it cannot be applied
  2001-09-09 11:11 [Caml-list] This expression is not a function, it cannot be applied Johann Spies
  2001-09-09 11:25 ` Remi VANICAT
@ 2001-09-09 11:38 ` Mike Leary
  2001-09-10  9:39   ` Johann Spies
  1 sibling, 1 reply; 4+ messages in thread
From: Mike Leary @ 2001-09-09 11:38 UTC (permalink / raw)
  To: Johann Spies; +Cc: ocaml

I'll take a stab at it...

Parentheses in OCaml aren't used like they are in function calls in C or
Perl; in OCaml they cause what's in them to be evaluated, as if you were
merely grouping expressions.  Then the druk_ry function gets applied to the
value of the expression in the parentheses, but since that expression...
well, isn't an expression, 'cause maand isn't a function, that doesn't
happen.   Function application happens w/o the parentheses.  So, I think
you want:

druk_ry maand hoofsom rente afbetaal;

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


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

* Re: [Caml-list] This expression is not a function, it cannot be applied
  2001-09-09 11:38 ` Mike Leary
@ 2001-09-10  9:39   ` Johann Spies
  0 siblings, 0 replies; 4+ messages in thread
From: Johann Spies @ 2001-09-10  9:39 UTC (permalink / raw)
  To: ocaml

Mike Leary <leary@nwlink.com> writes:

> Parentheses in OCaml aren't used like they are in function calls in C or
> Perl; in OCaml they cause what's in them to be evaluated, as if you were
> merely grouping expressions. 

That was my problem.  I have used the parentheses as I have used them
in Python and Pascal.  Thanks to you and Remi pointing this out to
me.


Johann
-- 
Johann Spies          Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch

     "Draw near to God and he will draw near to you.  
      Cleanse your hands, you sinners; and purify your  
      hearts, you double minded."       James 4:8 
-------------------
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


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

end of thread, other threads:[~2001-09-10  9:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-09 11:11 [Caml-list] This expression is not a function, it cannot be applied Johann Spies
2001-09-09 11:25 ` Remi VANICAT
2001-09-09 11:38 ` Mike Leary
2001-09-10  9:39   ` Johann Spies

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