3 ms·
The topic here isn't so much the order but whether "of" in int_of_string matches a common/typical usage of the word. From the other comments sounds like its lo
by esrauch 3y ago
The topic here isn't so much the order but whether "of" in int_of_string matches a common/typical usage of the word.
From the other comments sounds like its local style for OCaml maybe because of some French lineage, but that "int_of_string" is a function that converts a string into an int was definitely not something that I would have assumed (as opposed to 'int_from_string' or something).
- IshKebab 3y agoIt doesn't sound especially weird to me and I'm not French. It's just "[create an] int [out] of [a] string" "from" would have made more sense.
- esrauch 3y agoThe words in brackets are doing all of the heavy lifting in your example though: "Of" without "out of" means "constituted by". If in isolation I saw "array_of_string" I'd definitely parse that as somehow being about str[], not "f(str) -> char[]"
- tome 3y agoWell, if the word order is the most important aspect (as it is to me) then you have to think of another word you can use instead of "of". I know that in my early Haskell programming I was writing `intOfString` where other Haskellers wrote `stringToInt`. I'm a native English speaker so it certainly had nothing to do with French! "Of" just seemed to fit naturally there. Do you think "From" or some other English word would be more natural?
- marcosdumay 3y agoThe Haskell culture clearly dictates "i = fromString s". And as a consequence, Rust has it standardized as "i = from s".
- tome 3y agoWhat do you do if you want to disambiguate the return type? I suppose `intFromString` works. I'm not sure what I chose `intOfString`. It's not because I'm French!
- marcosdumay 3y agoYou would declare the type of the returning value: (i :: Int) = fromString s Although once in a while it's useful to make a short synonym for disambiguating the type, x_of_y is certainly not a short synonym, so it's not commonly used.