Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Dustin Sallings <dustin@spy.net>
To: Caml Mailing List <caml-list@inria.fr>
Subject: [Caml-list] type error in Set
Date: Fri, 5 Dec 2003 15:23:24 -0800	[thread overview]
Message-ID: <05C74CE4-277A-11D8-8B9B-000393CFE6B8@spy.net> (raw)


	I have an error I don't quite understand.  Can someone give me a clue? 
  I get an error in the following code:

module StringSet = Set.Make(String);;

let main() =
     let allFields = Fileutils.fold_file_lines
         (fun l m -> StringSet.add l m) StringSet.empty Sys.argv[1] in
     print_endline("All fields --");
     StringSet.iter print_endline allFields;
     print_endline("/All fields --");
;;


	It fails to compile on the due to the the following error (where 
18/30-31 is the m in ``(fun l m -> StringSet.add l m)''


File "spreadsheetPivot.ml", line 18, characters 30-31:
This expression has type 'a -> 'b but is here used with type
   StringSet.t = Set.Make(String).t


	The documentation for fold_file_lines looks like this:
		``val fold_file_lines : (string -> 'a -> 'a) -> 'a -> string -> 'a''
	and I know ``StringSet.add "hello" StringSet.empty'' works.

	fold_file_lines is defined as


let fold_file_lines f init_value fn =
     operate_on_file (fold_lines f init_value) fn
;;


	where operate_on_file is


let operate_on_file f fn =
     let ch = open_in fn in
     try
         let rv = f ch in
         close_in ch;
         rv
     with x ->
         close_in ch;
         raise x
;;


	and fold_lines is


let rec fold_lines f init_value ch =
     let line,eof = try (input_line ch), false
         with End_of_file -> "", true
     in
     if eof then
         init_value
     else
         fold_lines f (f line init_value) ch
;;


-- 
Dustin Sallings

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


             reply	other threads:[~2003-12-05 23:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-05 23:23 Dustin Sallings [this message]
2003-12-06  0:10 ` Dustin Sallings

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=05C74CE4-277A-11D8-8B9B-000393CFE6B8@spy.net \
    --to=dustin@spy.net \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox