caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] applying labled argument error
@ 2013-11-09  3:33 Jean Saint-Remy
  2013-11-09  4:27 ` Eric Cooper
  2013-11-09 10:07 ` Gabriel Kerneis
  0 siblings, 2 replies; 6+ messages in thread
From: Jean Saint-Remy @ 2013-11-09  3:33 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 565 bytes --]

Hi,

I am running ocaml 3.12.1 and getting an error message. Is it an incompatible version error or a missing 'core' module?

let permute array = 

  let length = Array.length array in
  for i=0 to length - 2 do
  let j = i + 1 + Random.int (length - i - 1) in 

  let tmp = array.(i) in 

  array.(i) <- array.(j);
  array.(j) <- tmp
  done ;;
let ar = Array.init 20 ~f:(fun i -> i) ;;
-: "Error: The function applied to this argument has type (int -> 'a) -> 'a array
     This argument cannot be applied with label ~f."

Best regards,

Jean

[-- Attachment #2: Type: text/html, Size: 1012 bytes --]

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

* Re: [Caml-list] applying labled argument error
  2013-11-09  3:33 [Caml-list] applying labled argument error Jean Saint-Remy
@ 2013-11-09  4:27 ` Eric Cooper
  2013-11-09 10:07 ` Gabriel Kerneis
  1 sibling, 0 replies; 6+ messages in thread
From: Eric Cooper @ 2013-11-09  4:27 UTC (permalink / raw)
  To: caml-list

On Fri, Nov 08, 2013 at 07:33:35PM -0800, Jean Saint-Remy wrote:
> let ar = Array.init 20 ~f:(fun i -> i) ;;
> -: "Error: The function applied to this argument has type (int -> 'a) -> 'a
> array
>      This argument cannot be applied with label ~f."

Put
    module Array = Arraylabels
at the top of your program, or explicitly call ArrayLabels.init.

-- 
Eric Cooper             e c c @ c m u . e d u

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

* Re: [Caml-list] applying labled argument error
  2013-11-09  3:33 [Caml-list] applying labled argument error Jean Saint-Remy
  2013-11-09  4:27 ` Eric Cooper
@ 2013-11-09 10:07 ` Gabriel Kerneis
  2013-11-09 17:57   ` Jean Saint-Remy
  1 sibling, 1 reply; 6+ messages in thread
From: Gabriel Kerneis @ 2013-11-09 10:07 UTC (permalink / raw)
  To: Jean Saint-Remy; +Cc: caml-list

On Fri, Nov 08, 2013 at 07:33:35PM -0800, Jean Saint-Remy wrote:
> I am running ocaml 3.12.1 and getting an error message. Is it an incompatible
> version error or a missing 'core' module?

Since you mention 'core', are you learning OCaml with "Real-World OCaml" (and
hence trying to use JaneStreet's Core library instead of the standard one)?
That would explain the discrepancy you are seeing.

Best,
-- 
Gabriel

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

* Re: [Caml-list] applying labled argument error
  2013-11-09 10:07 ` Gabriel Kerneis
@ 2013-11-09 17:57   ` Jean Saint-Remy
  2013-11-09 18:39     ` Anthony Tavener
  2013-11-09 18:42     ` Anil Madhavapeddy
  0 siblings, 2 replies; 6+ messages in thread
From: Jean Saint-Remy @ 2013-11-09 17:57 UTC (permalink / raw)
  To: Gabriel Kerneis; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1331 bytes --]

Hi,

I've been working out some of the examples in the https://realworldocaml.org/v1/en/html/a-guided-tour.html, which does utilize JaneStreet 'core' library. The new ocaml website is very impressive, as it allows you to dive right in into very fascinating idiomatic ocaml expressions. Just launching ocaml toplevel though is not enough. 

let sum list = 

  let sum  = ref 0 in 

  List.iter list ~f:(fun x -> sum := !sum + x);
  !sum ;;
-: Error: The function applied to this argument has type 'a list -> unit
   This argument cannot be applied with label ~f

Jean




On Saturday, November 9, 2013 5:07 AM, Gabriel Kerneis <gabriel@kerneis.info> wrote:
 
On Fri, Nov 08, 2013 at 07:33:35PM -0800, Jean Saint-Remy wrote:
> I am running ocaml 3.12.1 and getting an error message. Is it an incompatible
> version error or a missing 'core' module?

Since you mention 'core', are you learning OCaml with "Real-World OCaml" (and
hence trying to use JaneStreet's Core library instead of the standard one)?
That would explain the discrepancy you are seeing.


Best,
-- 
Gabriel

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

[-- Attachment #2: Type: text/html, Size: 2882 bytes --]

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

* Re: [Caml-list] applying labled argument error
  2013-11-09 17:57   ` Jean Saint-Remy
@ 2013-11-09 18:39     ` Anthony Tavener
  2013-11-09 18:42     ` Anil Madhavapeddy
  1 sibling, 0 replies; 6+ messages in thread
From: Anthony Tavener @ 2013-11-09 18:39 UTC (permalink / raw)
  To: Jean Saint-Remy; +Cc: Gabriel Kerneis, caml-list

[-- Attachment #1: Type: text/plain, Size: 2367 bytes --]

This is a bit of a pickle. For Real World OCaml to be a great book for
OCaml almost requires Core to become the stdlib. Core is a pretty nice body
of work, but I'm not a user of it myself, and I've been unable to decide if
I'd like it as the standard library. There is a very strong flavor to the
style. I suppose the official standard library has a bit of an
"exceptional" flavor, but aside from that I feel it doesn't impose anything.

Jean, for you example, the List.iter line using the standard library would
be:

    List.iter (fun x -> sum := !sum + x) list;

This kind of confusion is certainly not good for learning a language
though! To resolve this, we need to clone a single person three times and
send each into an alternate future: one continuing with standard library
as-is, one with Core, and one with Batteries. Then bring them back so they
can argue amongst each other about what was better. :)


On Sat, Nov 9, 2013 at 10:57 AM, Jean Saint-Remy <jeansaintremy@yahoo.com>wrote:

> Hi,
>
> I've been working out some of the examples in the
> https://realworldocaml.org/v1/en/html/a-guided-tour.html, which does
> utilize JaneStreet 'core' library. The new ocaml website is very
> impressive, as it allows you to dive right in into very fascinating
> idiomatic ocaml expressions. Just launching ocaml toplevel though is not
> enough.
>
> let sum list =
>   let sum  = ref 0 in
>   List.iter list ~f:(fun x -> sum := !sum + x);
>   !sum ;;
> -: Error: The function applied to this argument has type 'a list -> unit
>    This argument cannot be applied with label ~f
>
> Jean
>
>
>   On Saturday, November 9, 2013 5:07 AM, Gabriel Kerneis <
> gabriel@kerneis.info> wrote:
>  On Fri, Nov 08, 2013 at 07:33:35PM -0800, Jean Saint-Remy wrote:
> > I am running ocaml 3.12.1 and getting an error message. Is it an
> incompatible
> > version error or a missing 'core' module?
>
> Since you mention 'core', are you learning OCaml with "Real-World OCaml"
> (and
> hence trying to use JaneStreet's Core library instead of the standard one)?
> That would explain the discrepancy you are seeing.
>
>
> Best,
>
> --
> Gabriel
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 4401 bytes --]

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

* Re: [Caml-list] applying labled argument error
  2013-11-09 17:57   ` Jean Saint-Remy
  2013-11-09 18:39     ` Anthony Tavener
@ 2013-11-09 18:42     ` Anil Madhavapeddy
  1 sibling, 0 replies; 6+ messages in thread
From: Anil Madhavapeddy @ 2013-11-09 18:42 UTC (permalink / raw)
  To: Jean Saint-Remy; +Cc: Gabriel Kerneis, caml-list

Dear Jean,

Please do go through the installation instructions at:
https://realworldocaml.org/install

The Real World OCaml tutorials assume that you use the "utop" toplevel rather than than the standard toplevel.  You also need to "open Core.Std" at the beginning of the toplevel to ensure that you're using the Core standard library.

So you need:

$ utop
# open Core Std ;;
# let sum list = 
  let sum  = ref 0 in 
  List.iter list ~f:(fun x -> sum := !sum + x);
  !sum ;;
val sum : int list -> int = <fun> 

It's possible to use the standard OCaml toplevel if you really want to, but you need to manually configure several settings that Utop sets by default (short-paths, and evaluation of Async Deferred.t values at the toplevel).

best,
Anil

On 9 Nov 2013, at 09:57, Jean Saint-Remy <jeansaintremy@yahoo.com> wrote:

> Hi,
> 
> I've been working out some of the examples in the https://realworldocaml.org/v1/en/html/a-guided-tour.html, which does utilize JaneStreet 'core' library. The new ocaml website is very impressive, as it allows you to dive right in into very fascinating idiomatic ocaml expressions. Just launching ocaml toplevel though is not enough. 
> 
> let sum list = 
>   let sum  = ref 0 in 
>   List.iter list ~f:(fun x -> sum := !sum + x);
>   !sum ;;
> -: Error: The function applied to this argument has type 'a list -> unit
>    This argument cannot be applied with label ~f
> 
> Jean
> 
> 
> On Saturday, November 9, 2013 5:07 AM, Gabriel Kerneis <gabriel@kerneis.info> wrote:
> On Fri, Nov 08, 2013 at 07:33:35PM -0800, Jean Saint-Remy wrote:
> > I am running ocaml 3.12.1 and getting an error message. Is it an incompatible
> > version error or a missing 'core' module?
> 
> Since you mention 'core', are you learning OCaml with "Real-World OCaml" (and
> hence trying to use JaneStreet's Core library instead of the standard one)?
> That would explain the discrepancy you are seeing.
> 
> 
> Best,
> 
> -- 
> Gabriel
> 
> -- 
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
> 
> 
> 


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

end of thread, other threads:[~2013-11-09 18:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-09  3:33 [Caml-list] applying labled argument error Jean Saint-Remy
2013-11-09  4:27 ` Eric Cooper
2013-11-09 10:07 ` Gabriel Kerneis
2013-11-09 17:57   ` Jean Saint-Remy
2013-11-09 18:39     ` Anthony Tavener
2013-11-09 18:42     ` Anil Madhavapeddy

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