3 ms·
It'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
by ubertaco 2y ago
It'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)