2 ms·
>The way argumentless functions must be declared with "function". Could you show an example, I don't get it? >The expression termination issue (";;") Strange
by ernst_klim 10y ago
>The way argumentless functions must be declared with "function".
Could you show an example, I don't get it?
>The expression termination issue (";;")
Strange, I've never used ";;" in my code, only in repl.
>Operators not being overloaded is annoying, although there's a valid argument for explicitness.
Overloading is harmful. It's definitely the wrong way to do
ad-hoc polymorphism, and OCaml have a polymorphic comparison operators, which brought so much headache. Type classes or modular implicits are the right way to do ad-hoc. Looking forward to see modular implicits in OCaml [1].
>For example, having a REPL without built-in readline support (rlwrap to the rescue)
What do you mean by "readline" support?
[1] http://ocamllabs.io/doc/implicits.html http://ocamllabs.io/doc/implicits.html
- eru 10y agoOCaml doesn't have argumentless functions.. But they do have functions that take a 'unit' argument.
- ernst_klim 10y agoI know, I've asked about this: >The way argumentless functions must be declared with "function". function is just a sugar for fun+match, what does it have to do with argumentlessness?
- sgrove 10y agoI think by "argumentless function" OP just means "a function taking a single, unnamed argument", which is what function does as opposed to fun in OCaml (As you say, function is just sugar for (fun arg -> match arg with .... ) - it's a common enough idiom to have some sugar in the syntax).
- lobster_johnson 10y agoSorry, I should have been clearer. As I'm aware you have the choice between several ways: let foo : unit -> unit = <code> let foo = function | <pattern match stuff> let foo = (function () -> <code>) let foo = (fun () -> <code>) I'm not an expert, but I guess this awkwardness comes from OCaml not having a dedicated function-declaration syntax; so if you do: let foo = do_stuff + 42; ...then you're obviously just defining a variable, which is evaluated right away. Which means that the only way to define a "procedure"-type function that takes zero arguments is the above. > What do you mean by "readline" support? Readline is a library that adds a line editor to a REPL. It adds keyboard shortcuts (arrow keys etc.), history, autocompletion, and so on. Unlike almost every single REPL out there (Python, Ruby, Haskell, etc.), OCaml doesn't come with built-in support, as far as I've been able to determine. You have to run "rlwrap ocaml" to get Readline into your REPL.
- wtetzner 10y agoYou can also do this: let foo () = <code>
- lobster_johnson 10y agoThat's news to me. Thanks!
- ernst_klim 10y ago() is just an empty tuple, so yes, you can write let f () =...
- ernst_klim 10y ago>Readline is a library that adds a line editor to a REPL. There is a great advanced REPL for OCaml if you need something beyond simple stuff: https://github.com/diml/utop https://github.com/diml/utop