<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/11/7e7da260aa46285715d49921794fa6a1"
  from="Peter Scott &lt;sketerpot@c...&gt;"
  author="Peter Scott"
  date="2003-11-20T03:32:19"
  subject="[Caml-list] Recursive apply function"
  prev="2003/11/3e56b235242226f208aa4773ba9575b9"
  next="2003/11/461606c4d3157a5a76a31d3c6191a03b"
  next-in-thread="2003/11/461606c4d3157a5a76a31d3c6191a03b"
  prev-thread="2003/11/a2140a10ae8f0fe8f4ff398f0fbd2ddc"
  next-thread="2003/11/200096eaceaa7d8ec65f137c52c25c57"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Recursive apply function">
<msg 
  url="2003/11/7e7da260aa46285715d49921794fa6a1"
  from="Peter Scott &lt;sketerpot@c...&gt;"
  author="Peter Scott"
  date="2003-11-20T03:32:19"
  subject="[Caml-list] Recursive apply function">
<msg 
  url="2003/11/461606c4d3157a5a76a31d3c6191a03b"
  from="Aleksey Nogin &lt;nogin@c...&gt;"
  author="Aleksey Nogin"
  date="2003-11-20T04:42:14"
  subject="Re: [Caml-list] Recursive apply function">
</msg>
<msg 
  url="2003/11/a98ffd2d35498010d7a28ae7289a6827"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2003-11-20T06:32:12"
  subject="Re: [Caml-list] Recursive apply function">
</msg>
<msg 
  url="2003/11/a67170a9ced404324482eedfe2026978"
  from="Ville-Pertti Keinonen &lt;will@e...&gt;"
  author="Ville-Pertti Keinonen"
  date="2003-11-20T10:45:53"
  subject="Re: [Caml-list] Recursive apply function">
</msg>
</msg>
</thread>

<contents>
I'm having an interesting disagreement with ocaml about types. I'm trying 
to make a function to imitate the lisp apply function. That is, I want to 
make a function which will apply another function to a list.

I came up with this code:

let rec apply f args =
   match args with
       arg :: rest -&gt; apply (f arg) rest
     | [] -&gt; f;;

let add x y = x + y;;
let x = apply add [2; 3];;
print_int x;;

As you can see, the idea is to go recursively applying the function to the 
first element of the list. Unfortunately, I get this message when run: 
"This expression has type 'a but is here used with type 'b -&gt; 'a", 
referring to the "(f arg)" part.

Is there a way around this?

-Peter

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

