caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] type error in Set
@ 2003-12-05 23:23 Dustin Sallings
  2003-12-06  0:10 ` Dustin Sallings
  0 siblings, 1 reply; 2+ messages in thread
From: Dustin Sallings @ 2003-12-05 23:23 UTC (permalink / raw)
  To: Caml Mailing List


	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


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

* Re: [Caml-list] type error in Set
  2003-12-05 23:23 [Caml-list] type error in Set Dustin Sallings
@ 2003-12-06  0:10 ` Dustin Sallings
  0 siblings, 0 replies; 2+ messages in thread
From: Dustin Sallings @ 2003-12-06  0:10 UTC (permalink / raw)
  To: Dustin Sallings; +Cc: Caml Mailing List


On Dec 5, 2003, at 15:23, Dustin Sallings wrote:

>         (fun l m -> StringSet.add l m) StringSet.empty Sys.argv[1] in

	Ugh, nevermind, misleading error message and too many programming 
languages.  :)

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


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

end of thread, other threads:[~2003-12-06  0:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-05 23:23 [Caml-list] type error in Set Dustin Sallings
2003-12-06  0:10 ` Dustin Sallings

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