Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] type error in Set
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-12-05 (23:23)
From: Dustin Sallings <dustin@s...>
Subject: [Caml-list] type error in Set

	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 "", 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
         let rv = f ch in
         close_in ch;
     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
     if eof then
         fold_lines f (f line init_value) ch

Dustin Sallings

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: