dbuenzli / fpath

File paths for OCaml
http://erratique.ch/software/fpath
ISC License
27 stars 10 forks source link

Question about of_string restricting result type to [`Msg] #12

Open andreypopp opened 6 years ago

andreypopp commented 6 years ago

I apologise if that's not the right place for this question but I wonder why Fpath.of_string restricts the type of its result:

val of_string : string -> (t, [`Msg of string]) Result.result

instead of

val of_string : string -> (t, [> `Msg of string]) Result.result

Because of that I have to use double coercion in my code where I have other variants in the error side of the result.

dbuenzli commented 6 years ago

I'm no longer sure exactly why. Some type error messages may be a bit less unwidely if you proceed that way but it might not be a good reason to do this and maybe this should be opened (I'm a bit unsure how much code that would break though).

Note that if you are using rresult you can use R.open_error_msg rather than coercions.

andreypopp commented 6 years ago

Thanks for clarification and for suggestion to use R.open_error_msg!