I'm trying to implement a particular algorithm. The algorithm isn't very well described but I do have an OCaml implementation. Problem is I don't know OCaml and I'm finding the syntax strange. So here's the first of what might be many questions. Apologies for any mistakes in terminolgy.
One part of the code I have looks like this
type alternative_text = string
type indent = int
module Line =
struct
type t = {s:alternative_text; i:indent}
let make s i = {s;i}
let text (l:t): alternative_text = l.s
let length l = String.length l.s
let indent l = l.i
end
My question concerns the line let text (l:t): alternative_text = l.s. I think I know what this is, a function Line.text which takes a Line.t object and returns the s field, which is a string.
My question concerns the (l:t): alternative_text syntax. This looks like it's specifying the type of the parameter and function result, but why is it necessary? As far as I know let text l = l.s would do exactly the same thing and the other functions are defined without using this extra syntax. So why is it being used here?
Thanks in advance.
textfunction but not for the others? - john