Live data from Hacker News

Why I love OCaml (2023)

mccd.space

291–300 of 313 posts

Re: Why I love OCaml (2023)

#291
post #277

> It just genuinely felt like the Go language designers didn’t want to engage with any of the ideas coming from functional programming. You'd be right. "The key point here is our programmers are Googlers, they’re not researchers. They’re typically, fairly young, fresh out of school, probably learned Java, maybe learned C or C++, probably learned Python. They’re not capable of understanding a brilliant language but we…

I am exactly the type of novice programmer described in the quotes. >have shifted their way of thinking rather extremely What could I read to shift my way of thinking? The signals & threads episode about OCaml strongly piqued my interest, and not because I have any JS delusions (they would never, lol).

Functional programming is a different way of thinking about solving problems. People say it's about thinking about "what you're trying to compute" versus "how you're computing it," but quite frankly that never made sense to me. I prefer to think about it in terms of thinking about relationships (FP) versus thinking about steps over time (procedural).

This, at least for me, brings the act of writing a specific piece of code more inline with how I think about the system as a whole. I spend less energy worrying about the current state of the world and more about composing small, predictable operations on relationships.

As for what you can read, I find it's just best to get going with something like OCaml or F# and write something that can take advantage of that paradigm in a relatively straightforward way, like a compiler or something else with a lot of graph operations. You'll learn pretty quickly what the language wants you to do.

Re: Why I love OCaml (2023)

#292
post #249

Earlier quoted context omitted.

TCL it's almost Lisp with strings instead of atom lists. I prefer it a little over Perl.

No macros, limited support for higher order functions. Its big drawback is the small ecosystem. I like TCL, but its not really comparable to lisp. Its definitely a great scripting language and is a lot more flexible than it gets credit for. It got a lot of things right. Event driven concurrency (and its got a good threading model) which is often given as a reason to use JS to right servers. Sandboxing untrusted code.…

> Unfortunately it never got traction.

Categorically not true. Tcl got a LOT of traction. Expect was everywhere. Tk kicked ass and took names. AOLserver, anyone? VLSI CAD stuff still uses it today.

It just got pushed out of the way over time. IMO, mostly because VB6 took its niche of easy GUI.

Re: Why I love OCaml (2023)

#293
post #13

OCaml’s REPL is lovely, but I found myself having some friction with initial startup. The build/package system was pretty convoluted, and I ended up choosing JS’s Core stdlib for my needs (a simple compiler). With the new multicore release it’d be cool to see OCaml in some more practical projects!

As an OCaml-curious, is this the community recommendation, to choose the Jane Street stdlib if you’re just getting started?

Many learning materials will push you that way, but the vast majority of FOSS packages don't use it.

There's nothing inherently wrong with using Jane Street's stdlibs if you miss the goodies they provide, but be aware the API suffers breaking changes from time to time and they support less targets than regular OCaml. I personally stopped using them, and use a few libraries from dbunzli and c-cube instead to fill the gaps.

Re: Why I love OCaml (2023)

#294

Earlier quoted context omitted.

Anecdotally we are using F# more than ever before, and it works for us for a large sized organisation. Fast code, it is keeping up with the .NET features that matter for that (e.g. spans), and tbh has still been getting better over the years. In fact I find some of the new features like Span, SIMD/intrinsics somewhat synergise with existing F# features (e.g. inline). C# IMO still hasn't quite caught up but is getting…

Interesting take. I agree with you mostly but regarding "community" I am more thinking of the side effects there in terms of _other_ people developing interesting libraries etc. I don't know if AI can change that but when using python, there is a feeling that there is an awesome quality library for just about anything.

I get that, which is why I said it is important for some people depending on the domain and I meant in general language communities. Python is different at least to me given AI and being the first target for not just software improvements but hardware usage (e.g. GPU accelerated specialised libs) and training materials/examples. It is the AI community not the Python community per se; the AI community just targets Python. JS is also a little different given browsers are so ubiquitous and their own target with JS being the main language that works there.

Otherwise in most mainstream platforms there is enough libraries for most things already; which includes .NET. It's rare not to find a well maintained lib for the majority of use cases in general whether it is .NET, Java, Go, etc which is why w.r.t long term risk a used platform is more important than the syntax of a language and its abstractions. Web frameworks, SDK's, DB drivers, etc etc are all there and generally well tested so you won't be stuck if you adopt F#. I evaluate on more objective metrics like performance, platform improvements, compatibility with other software/hardware, etc etc. It isn't that risky to adopt F# IMO (similar risk to .NET in general) - to me its just another syntax/tool in my toolbelt with some extra features than usual if I'm developing things typical in that .NET/Java/Go abstraction level.

Re: Why I love OCaml (2023)

#295

Earlier quoted context omitted.

TypeScript certainly has a more complicated and flexible type systems in many respects, but it is not the same w/r/t safety. It is quite common to run across `any`s all over the place in TypeScript code, and there is no such thing in OCaml. TypeScript's systems is explicitly unsound (i.e., not fully type safe) by design: https://www.typescriptlang.org/docs/handbook/type-compatibil...

Ocaml has exactly the same kinds of escape hatches, like Obj.magic or unsafe accessors. The way I see it. it's a matter of community practice more than language capabilities. Typescript in practice has has the safety net of being interpreted rather than compiled, so I guess people tend to abuse its type flexibility more. But if you write without the escape hatches in both languages, in my experience the safety is exa…

First off, the escape hatches in TypeScript are way too accessible compared to OCaml: `JSON.parse(...) as MyInterface` is everywhere and completely broken.

And second, you're dismissing the fact that TypeScript is unsound, even worse it is so by design. Easy examples: uninitialized variables holding undefined when their type says they can't [1]; array covariance [2]; and function parameter bivariance, which is part of the TypeScript playground's own example on soundness issues [3] but at least this one can be configured away.

C# and Java made the same mistake of array covariance, but they have the decency of checking for it at runtime.

[1]: https://www.typescriptlang.org/play/?#code/DYUwLgBAHgXBB2BXA... [2]: https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAllApg... [3]: https://www.typescriptlang.org/play/?strictFunctionTypes=fal...

As for your example, I agree that TypeScript unions and singleton types are powerful, but I can't see what are you speficially missing here that pattern matching and maybe an additional variant type doesn't get you in OCaml. You get exhaustiveness checking and can narrow the value down to the payload of the variant.

Re: Why I love OCaml (2023)

#297
post #96

> why isn’t OCaml more popular I've used OCaml a bit and found various issues with it: * Terrible Windows support. With OCaml 5 it's upgraded to "pretty bad". * The syntax is hard to parse for humans. Often it turns into a word soup, without any helpful punctuation to tell you what things are. It's like reading a book with no paragraphs, capitalisation or punctuation. * The syntax isn't recoverable. Sometimes you can…

That third issue is very annoying. C++ in visual studio often has that and I'll help someone who has like 2,000 weird errors and my response is usually "looks like a missing semicolon to me" and they're like "????" Why wouldn't it be able to just say that.

Re: Why I love OCaml (2023)

#298

Earlier quoted context omitted.

It's a matter of trends: F# is losing compatibility with the overall CLR ecosystem due to the churn in C# features with poor F# interop, but F# has already mingled its design with the CLR's, too much to live on its own as a native language. Plus its compiler is slow and the tooling is getting increasingly unstable. Meanwhile, OCaml got rid of its global lock, got a really fast-compiling native toolchain with stable a…

> has an edge on some domains due to having unboxed types If a language makes "unboxed types" a feature, a specific distinction, and has to sell "removing global lock" as something that is a massive breakthrough and not table stakes from 1.0, it can't possibly be compared to F# in favourable light.

OCaml predates multicore CPUs. Having a global lock was basically free at the time it was invented. It's totally crazy to dislike a language because the authors made a decision that was obviously correct at the time.

Re: Why I love OCaml (2023)

#299
post #276

Earlier quoted context omitted.

A lot of these are learning curve issues, but once you scale them you still permanently suffer with a very deficient, fragmented ecosystem. Until you have built up your own curated set of dependencies for your business stack, anyway. > * Ocamlfmt is pretty bad. It thinks it is writing prose. It will even put complex `match`es on one line if they fit. Really hurts readability. I suggest configuring ocamlformat to use…

With all the issues, how does janestreet love it so?

[deleted]

Re: Why I love OCaml (2023)

#300
post #220

Earlier quoted context omitted.

The Windows support is bad because OCaml is a PL designed by people who are deep in Linux life. Windows is not something that keeps them up at night. (Which isn't to say they didn't try, just, you know, not as much as it takes) One of the things people often neglect to mention in their love letters to the language (except for Anil Madhavapeddy) is that it actually feels UNIXy. It feels like home.

Caml was developed in 01985, Linux was first released in 01991, and Caml was extended into OCaml in 01996. I don't think the developers were using Linux at the time; SunOS 4 would be my best guess. I didn't work on it, but I was in the sort of internetty environment that OCaml came from, and I was using Solaris at work and got my first Linux box at home. As another commenter mentioned, the command line follows Unix c…

Forgive me for implying the Linux lifestyle and UNIX lifestyle were anything close to the same thing.

I will turn in my Plan 9 install media and my copy of The Design and Implementation of the 4.3BSD Operating System at the nearest DEC service center.

Post reply on HN