4 ms·
Another thing I personally hate about OCaml's syntax is the order of generic parameters being backwards. I know why it's like that, but it still doesn't make an
by SkiFire13 2y ago
Another thing I personally hate about OCaml's syntax is the order of generic parameters being backwards. I know why it's like that, but it still doesn't make any sense to me both as a programmer and as a non-native english speaker.
- nsonha 2y agoI'm not even an ocaml dev and I prefer how it reads and types to that of C family generics.
- SkiFire13 2y agoWould you mind expanding on why do you prefer it? I'm not too focused on e.g. not using angle brackets, which is pretty common in the C family (though funnily enough they are not used in C), but rather on the order with type arguments being before the generic type, for example the type of lists of integers being `int list` rather than `list int`.
- nsonha 2y agoMy mother toungue has the reverse order to English grammar too, but I've spoken English long enough for that to not matter. If we're talking about, say, consistency with function syntax, then to me a function is a verb, and a type is a noun, hence still consistent. I mentioned the typing experience because I hate to have to 1. open and close braces 2. press shift while typing [2] is also the reason I prefer generics in python and scala than that of java and C#
- ubertaco 2y agoIt's definitely quirky in its inconsistency, but type 'a Tree = | Node of ('a Tree, 'a Tree) | Leaf of 'a Is saying "The possible cases for the type describing an 'a Tree are: a Node of two other 'a subtrees, or else a Leaf of an 'a." Then when you concrete-ize it, you have an "int Tree" or a "string Tree". This is a little clearer with thinking of the List datatype: this is a number list, that's a string list, that's a grocery list, this is a guest list...etc. One nice thing in F# is that there's an ability to "standardize" how you write generics to look more like the (admittedly arbitrary) way that C# or Java or C++ write them: type Tree<'a> = | Node of (Tree<'a>, Tree<'a>) | Leaf of 'a
- SkiFire13 2y ago> This is a little clearer with thinking of the List datatype: this is a number list, that's a string list, that's a grocery list, this is a guest list...etc. That's what I was referring to when I said "as a non-native english speaker". In my native language I would say those in a way that's more similar to "a list of numbers", etc etc. > One nice thing in F# is that there's an ability to "standardize" how you write generics to look more like the (admittedly arbitrary) way that C# or Java or C++ write them: Arguably this order (type then generic arguments) is not that arbitrary because this is effectively a type level function, so it makes sense that it uses the same order. However the angle brackets are indeed arbitrary, and IMO to be more consistent the same syntax as function application should be used. For practical purposes though this may make a type's syntax too similar to an expression, so it may not be the best choice (unless you're in a language where types are actually values)
- deleted 2y ago[deleted]