Hello there! It’s me again, the OCaml noob.
type choice =
| Add_semicolon
| Add_keyword_in
| Add_nothing
Now I know that you can use let f x = ...
to define a function but I still get confused whether to add the keyword in
at the end of the definition.
Most of the time, if I add in
at the end of function definition, the compiler throws an error.
But in some cases if I don’t add in
, neither me or the compiler know where to distinguish the scopes. e. g.
let myfunction a b =
match a with
| 1 -> true
| _ -> false
let another_function x =
(* Skipping... *)
I noticed that in this case, in
was not allowed.
But sometimes code like this
let some_fn (x) (y) (z): unit =
(* function def here *)
let () = some_fn 1 2 3 (* One more thing, do I need a semicolon here? *)
Causes some error like “Unable to find symbol ‘some_fn’” and the compiler asks me to add a rec
to the function definition because it thinks I’m trying to call the function itself inside of the definition.
I’m watching CS3110 YouTube tutorials these days, but
-
Michael Ryan Clarkson uses
utop
in the tutorial series, which means most of the time a definition ends with;;
which (I heard) considered “Bad Coding Style” when comes to source code editing outsideutop
- As a newcomer from C family languages like Python, it takes time to get used to
let ... in
and seriously, what’s the difference between OCaml function definitions and Python? You always write definitions separately, isn’t it?
The compiler complains too much about me adding in
here and there that I had to spend most of my time setting up OCaml LSP instead of learning. Is there some kind of easy-to-remember ‘rule’ or cheatsheet to get me through these?