From: <syl...@po...> - 2004-02-01 12:58:46
|
Hello, On Sun, Feb 01, 2004 at 11:22:14AM +0100, Nicolas Cannasse wrote: > Just a little additionnal suggestion about SysUtil : > > SysUtil is heavily relying on the Unix module for its implementation, and > that's ok. But only one feature ( the Match pattern to match the filename > using a regexp) is using the Str module. In order to reduce dependencies, I > think you should abstract the Match, using an user define regexp matching. > For exemple : > > in SysUtil.mli : > --- > > val configure_regexp : make:(string -> 'a) -> test:('a -> bool) -> unit > > in SysUtil.ml : > ----- > let regexp_make= ref (fun _ -> failwith "Regexp is not configured") > let regexp_test = ref (fun x _ -> failwith "Regexp is not configured"; x = > 0) (* we need to give a type here for ungeneralized variables *) > > let configure_regexp ~make ~test = > regexp_make := Obj.magic make; (* we need to cast here because the type > we need is slighty different *) > regexp_test := Obj.magic test > > * and in testing Match : > let reg = !regexp_make str in > fun x -> !regexp_test reg x > > Then the user could write : > > SysUtil.configure_regexp Str.regexp Str.string_match > before making any Match > > ( we can also use only one function with currying trick : > SysUtil.configure_regexp (fun reg -> let reg = Str.regexp reg in > (Str.String.match reg)) > but it's then less comprehensible for the user ) > > Regards, > Nicolas Cannasse > > > Ok, you are perfectly right. I will remove the Str test and replace it by a user provided test... But i won't use obj.magic to cast regexp... I prefer let the user do some more work to have something fully ocaml compliant than using a clever trick that is not documented ( personnal point of view on obj.magic ). Thank you for your remark. Kind regard Sylvain LE GALL |