I think sepp2k already answered most of the questions, but I would like to add a couple of points that can explain how the F # / OCaml compiler interprets the code and explains some common uses.
As for the symbol ' - this is only part of the name (a valid identifier begins with a letter and then contains one or more letters, numbers or characters ' ). It is usually used if you have a function or value that is very similar to some other, but in some way new or changed.
In your example, xs is a list to be summed, and pattern matching decomposes the list and gives you a new list (without the first element) that you need to sum, so it's called xs'
Another common use is to declare a function of a local utility that implements functionality and accepts an additional parameter (usually when writing tail recursive code):
let sum list = let rec sum' list res = match list with | [] -> res | x::xs -> sum' xs (res + x) sum' list 0
However, I think that there is usually a better name for the function / value, so I try to avoid using ' when writing code (I think this is not particularly readable and, moreover, it does not paint correctly on StackOverflow!)
As for the symbol :: - as already mentioned, it is used to create lists from one element and a list ( 1::[2;3] creates a list [1;2;3] ). However, it is worth noting that a symbol can be used in two different ways, and it is also interpreted by the compiler in two different ways.
When creating a list, you use it as an operator that creates a list (the same as when using + to add two numbers). However, when you use it in a match construct, it is used as a template, which is another syntax category - the template is used to decompose the list into an element and the remainder, and it succeeds for any non-empty list
// operator let x = 0 let xs = [1;2;3] let list = x::xs // pattern match list with | y::ys -> // ...
source share