12 ms·
Have you ever had one of those notepads with the kind of paper that made you want to write something, anything, even though you had nothing to write about? OCam
by jasim 8y ago
Have you ever had one of those notepads with the kind of paper that made you want to write something, anything, even though you had nothing to write about? OCaml is just like that to me.
I stroll through the internet aimlessly and I find a page that mentions OCaml and my eyes light up; I see an .ml file and savor how it looks - functions written with great economy of expression, pattern matching through which data flows in well-defined pathways, abstract data types forming a network of rugged pipes and girders that makes invalid states impossible; and .mli files that presents modules like classic prose -- no hedges, contortions, or obscurities that undercut the reader's ability to understand the flow of data and the pathways through which it flows.
"Expression, carrying the elegance that comes from compressed energy, is like a perfectly tuned stringed instrument: the strings are taut to exact degrees to correspond to exact pitches that stand in exact relations to one another. The pitches and their relations exist before the strings are tuned. Each string is tuned to a pitch and the results are judged by comparison to this pre-existing reality. A musician tuning an instrument is not finished until everything is exactly right, but once it is exactly right, there is simply nothing left to do." -- Clear and Simple as the Truth: Writing Classic Prose, Thomas, Turner.
- deleted 8y ago[deleted]
- iaabtpbtpnn 8y agoSeriously, it is so good. I wish I could still program in OCaml professionally, as I did in the past.
- arcturus17 8y agoOCaml is the coolest language I’ve ever used. It’s the backbone of Harvard’s Intro to CS II, where they explain programming language paradigms with a heavy emphasis on the functional. OCaml’s expressiveness really shines through - I remember fondly how small yet powerful the language feels. Unfortunately, I don’t know what to build with it... I’m the kind of person that builds projects for professional advancement, which curtails my creativity. I’ve thought of making a simple web server. Or maybe learning ReasonML. Any suggestions welcome.
- loup-vaillant 8y agoOCaml really shines when your problem is data in, data out, and the transformation is non-trivial. So, maybe try compiling or generating stuff. I have two examples of my own: USSM¹, a simple static web site generator, and Monokex, a secure handshake generator like the Noise explorer (except much smaller, much simpler, and very incomplete). [1]: http://loup-vaillant.fr/projects/ussm/ http://loup-vaillant.fr/projects/ussm/ [2]: https://github.com/LoupVaillant/Monokex https://github.com/LoupVaillant/Monokex
- vram22 8y ago>OCaml really shines when your problem is data in, data out, and the transformation is non-trivial. So do you think it would be a good choice for creating a make-like tool, in which you want to support doing transitive / hierarchical makes, like target A depends on B, and B on C, so if C is newer than A, the tool should build B from C and then A from B, and other such variations? Working on such an idea, currently in Python, and have an interest in and am reading about OCaml, hence asking. I think the work may involve a topological sort.
- loup-vaillant 8y agoYes, that's the kind of thing I'd reach Ocaml for.
- vram22 8y agoGreat, thanks.
- yawaramin 8y agoYou should check out at least a couple of things: - The Dune build system for OCaml, also written in OCaml, does exactly what you are describing: https://dune.build/ https://dune.build/ - Jane Street's Incremental library lets you build auto-updating computations which change whenever their inputs change: https://github.com/janestreet/incremental https://github.com/janestreet/incremental Honourable mention: Thomas Leonard's really interesting series where he describes rewriting his dependency management tool, 0install, from Python to OCaml http://roscidus.com/blog/blog/2014/06/06/python-to-ocaml-retrospective/ http://roscidus.com/blog/blog/2014/06/06/python-to-ocaml-ret...
- chrischen 8y agoYou can use this: https://reasonml.github.io/reason-react/ https://reasonml.github.io/reason-react/ And you can interop between reason and Javascript!
- nraynaud 8y agoI have a project that uses it, Meh. when people use Camlp4, it's a pain to read, the stuff is had to follow when it's a wall of text because of the level of indirection, Lwt makes everything hard. When I was 20, I thought Ocaml was the best thing in the world, because I was writing it. Now, after years without using it, I have to maintain other people's code, my opinion changed.
- ms013 8y agoI use ocaml daily for work - our core product is written in it. We actively avoid anything that deviates from the base language for reasons of clarity. No camlp4, no lwt, no fanciness other than some of the batteries libraries that improve on the std library. It does occasionally mean we type in more than we would if, say, we used extensions to give us Haskell-like do notation for monadic code, but at the end of the day we err on the side of being very conservative.
- rwmj 8y agoThat's pretty much how we wrote the virt tools[1], basically we rely on the OCaml compiler, findlib, and not much else. [1] https://github.com/libguestfs/libguestfs https://github.com/libguestfs/libguestfs
- noir_lord 8y agoWow. I had not seen your project before and this looks exactly like the right hammer for a problem I needed to hit a week or so go.
- StreamBright 8y agoIsn't PPX supposed to replace Camlp4?
- Tommah 8y agoI think so. See https://discuss.ocaml.org/t/is-camlp4-being-deprecated-in-favor-of-ppx/979/ https://discuss.ocaml.org/t/is-camlp4-being-deprecated-in-fa... I recently came back to OCaml (and js_of_ocaml) after being away for a few years. In the time I was gone, js_of_ocaml moved from camlp4 to ppx. (edited to fix link)
- akhilcacharya 8y agoIt scares me how much I relate to this but don’t have the eloquence to express it like you did. I’ve evaluated it for a lot of smaller stuff I’ve needed to get done, but ultimately it just ends up being easier to use a framework or language that I already know.
- narimiran 8y ago> Have you ever had one of those notepads with the kind of paper that made you want to write something, anything, even though you had nothing to write about? That's exactly my experience with F# (not surprising, knowing how similar OCaml and F# are), but until I read your comment I didn't know how to explain this joy of reading and writing code in it.
- codetrotter 8y ago> Have you ever had one of those notepads with the kind of paper that made you want to write something, anything, even though you had nothing to write about? Yup! The “official” notepads of my university are nice quality paper. They cost more but I enjoy them so much that I buy them anyhow. Conversely, I’ve also had notepads with paper that felt so horrible to write on that I were unable to use them. Fortunately a friend of mine uses ink instead of mechanical pencil so for her using those notepads was not a problem so I gave them to her rather than having them sit in a closet or having to hand them over to recycling unused.
- noir_lord 8y agoFor me the absolute sweetspot is these https://www.wilko.com/en-uk/wilko-graph-pad-a4-50-sheets-80gsm/p/0348711 https://www.wilko.com/en-uk/wilko-graph-pad-a4-50-sheets-80g... They are ridiculously cheap but the paper is lovely and they work fantastic with my ballpoints of choice. I buy them 16 at a time.
- codetrotter 8y agoThey are probably nice but I think shipping them to Europe (where I live) would be very expensive probably :P
- laurentl 8y agoThanks for this (and the child comments). I was just about to post a “which functional language should I pick up” ask HN but I got most of my answer from this thread :D I learned to program in Caml (20 years ago now... it still seems like yesterday) but switched to curly brackets land when I started working, and more recently Python. Last month I started reading Learn You a Haskell for Great Good and that made me nostalgic for FP. Haskell’s syntax and strict management of side effects is a bit of a turn-off though. The article and the comments have firmly put me in the Caml camp, but now I have to figure out which version (OCaml, F#, ReasonML) to go for. Advice or opinions on the topic are welcome!
- jasim 8y agoIf you're writing anything for the browser, then I'll solidly recommend Reason. It works out of the box and ReasonReact is much more ergonomic compared to vanilla React + ImmutableJS + Redux + TypeScript combo. And there is a growing community around that use case in the Reason world. If you want to write a command-line application, you can choose either OCaml or Reason, depending on your taste of syntax - both compile to native statically linked binaries. If you're doing anything related to compilers, OCaml is particularly suited for that, and you'll be in very good hands with Menhir (see: https://pl-rants.net/posts/case-for-new-lang/ https://pl-rants.net/posts/case-for-new-lang/). Another systems software written in OCaml is unison (https://github.com/bcpierce00/unison https://github.com/bcpierce00/unison), which is a file synchronization tool with a clear specification. But if you want to write database backed web application servers in OCaml, with sessions, background jobs, admin interfaces, ORMs, database migrations and all that jazz, then you might want to give F# a go, or Haskell which has a better story around it. I do have a tiny Node server written in Reason that I use as an API endpoint but if I were to build a full-fledged system, there is nothing yet in the OCaml world like Rails or Django.
- laurentl 8y agoThanks for the feedback. At this stage the goal is purely to dabble in FP with "Advent of Code" style mini-programs, and basically opening my developer chakras. An added benefit would be to use this new language at work, which means that the size of the ecosystem (3rd-party modules, frameworks, etc.) can be a factor - one in which I guess OCaml is behind F# and Reason?
- Tommah 8y agoIf you have any web projects, you may be able to find a place for js_of_ocaml in one of them. I use it in a web app of mine. I started out writing the client-side scripting in plain JS (as opposed to React/Vue/etc.), but I am using js_of_ocaml lately to implement some more complex logic.
- Barrin92 8y agoYep I know the feeling. I like Ocaml (and also Clojure) so much that it's one of the few languages were I'll actually don't really care about what I'm programming on as long as I get to use the language. Building real things is great, but honestly for me one of the most satisfying things is just programming in an expressive and clean way for its own sake. It's great when you get a language or a tool that faciliates that.