4 ms·
The syntax is pretty much like Python and ruby: “end” to declare end of block statements and colon to start a block statement. But why to use “fun” to declare a
by Maksadbek 5y ago
The syntax is pretty much like Python and ruby: “end” to declare end of block statements and colon to start a block statement. But why to use “fun” to declare a function when “def” could be used.
The same in other languages: function, func, fun, fn, etc.
- Okkef 5y agopython doesn't use end. To be honest, as a python programmemr the syntax looks quite alien.
- scns 5y agoMaybe because it should be fun to use? NSI. I prefer fun to fn and func, because it aligns nicely with four spaces a tab formatting.
- skrishnamurthi 5y agoBecause `def` suggests there is only one kind of thing we're defining (functions), when we could be defining any number of things: functions, type aliases, algebraic datatypes, tests, etc. So we use `fun` for functions, and different keywords (e.g., `examples` for examples) for other things. You should really be questioning why `def` was used for functions.
- Mikeb85 5y agoLol the syntax is basically Ocaml with a tad less noise.