Why use ocaml




















OCaml comes with an extensive standard library with good data structures, POSIX system calls, and networking primitives. True Static Scope with Closures. OCaml has true nested scope: in other words, you can define functions inside of other functions recursively. This may not sound impressive -- after all, nested functions have been around since Algol 60 -- until you remember that C's "innovation" of not allowing nested functions was widely copied and many languages that were designed after C likewise disallow it.

Nested functions as an encapsulation technique gives you the most bang for the buck: it's dead simple, with no special syntax or semantic restrictions to learn, and yet lets you break your program down into many tiny little functions which are truly easy to debug or just write correctly in the first place.

OCaml's static scope lets you avoid passing dozens of parameters to these inner functions, and allows you to safely capture the local variables of enclosing functions, forming closures that replace many uses of:. Of course, OCaml has more powerful encapsulation techniques -- parameterized modules and true objects -- for when you need them; but with nested functions and static scope, you won't need them as often. Pattern Matching. OCaml allows you to use pattern matching in your function definitions.

As a result, the structure of the function models the structure of the data it's processing, making it easy to see base cases and harder to miss a case, as you might using conditionals. In fact, OCaml's type checker can often warn you that you've left out a case.

For example, this definition:. Pattern matching works both with the built-in data types and with user-defined data types. Simultaneously, pattern matching eliminates the need for multiple-value returns, and serves as a general-purpose destructuring bind. Finally, many functional languages restrict pattern matching syntactically to function definitions; OCaml's pattern matching is an expression that can be used anywhere.

OCaml gives you namespaces, information hiding and abstract types via its module system. The module system is strongly and staticly typed, even across file boundaries, which allows separate compilation.

Syntax Extension. It wasn't the constructs that made it look hard, those actually looked really neat. It was trying to learn an entirely different meaning for '! Lisp at least looks so different that it's easy to avoid misinterpreting small pieces of it as c. If you want a language to use in real-time embedded systems, you need pointers and you can't afford a GC. And when talking to other developers those who heard something about Ocaml I always get the impression that they think of OCaml as an "education-only" language I like O'caml a lot I've implemented a bunch of things using it, compiler, interpreters, system to communicate with C Sign up to join this community.

The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Why isn't OCaml more popular? Ask Question. Asked 12 years, 10 months ago.

Active 8 years, 6 months ago. Viewed 65k times. Juliet Juliet 2, 6 6 gold badges 25 25 silver badges 23 23 bronze badges. Active Oldest Votes. With that disclaimer, here are some points that are suggestive, most important first: The first mature C compiler appeared in ; the first mature OCaml compiler appeared in the late s. Norman Ramsey Norman Ramsey 2, 1 1 gold badge 17 17 silver badges 15 15 bronze badges. OCaml is a relatively recent ML dialect, born about same time as Java.

ML dialects found a niche in theorem proving and research, but have since been the industry standard in financial institutions. I wouldn't call ML the "industry standard in financial institutions.

Companies like Jane Street are the exception, not the rule. Perl is a "software artifact" - the only definition of Perl is "the language that perl 1 interprets" - and yet it's rather popular.

Python and Ruby were "software artifacts" for a long time. Chris: IMO this is one reason that Perl is losing mindshare. As to predictability, I think OCaml actually beats C in that realm, with the level of optimization that is expected of C compilers, and the fragility of many of those optimizations. OCaml's compiler is very literal about what it compiles your code into. Show 5 more comments. The result was popularity. Money can solve a lot of problems.

This was maybe true 10 years ago. Let me know when I can "cabal install" an OCaml library. Anyway, just because I said something bad about your favorite languages doesn't mean you have to stop using it.

So no need to get emotional. No, I meant programming in general. If you can't understand functional programming, you probably can't understand the other concepts either.

I don't buy this. OCaml has plenty of libraries for basic day-to-day programming stuff, and if it became more popular, people would write more. Every language started out with few libraries. How about a link to these libraries?

Why did more than 0 people upvote someone who claims a language has no usable hash table implementation? I can't stand languages that build in useless crap like regular expressions and dictionaries in them, a language should be as decoupled as possible from libraries, to keep the critical TCB down.

A language that relies on dictionaries to get anything done is utter crap. Show 8 more comments. I like OCaml a lot as a language.

The standard library can sometimes have an inconsistent feel. I would not say its type system is too strong, but rather not expressive enough, type class ala Haskell would help a lot. I feel this weakens your argument a bit though I agree with it. The OCaml debugger, is the only one I know that can step-backwards, as well as forwards.

Add a comment. Sure, but Java and PHP are popular, and you can't use those in embedded systems. Usability in embedded systems does not have much influence over language popularity. The original question asked about embedded systems so I provided a specific reason why it might not be used.

And as a side note you can use Java - just not for real-time same goes for C. Java itself isn't real time. Anything with a garbage collection mechanism can't be. There are many real time garbage collectors. Java implementations do use them and Java is used in real time applications. Show 6 more comments. Chris Conway Chris Conway 1 1 silver badge 5 5 bronze badges. According to Wikipedia, ML isn't much younger, it's only one year younger for C v.

The rest of your explanation I think is right on the money. ML dates back to , OCaml is from Christian Lindig Christian Lindig 1 1 silver badge 4 4 bronze badges. Why you'd choose Erlang over either I'm not sure: Erlang is not statically typed and, as for me, after some frustrating experiences with it, I'd take ML over it any day.

I was taught Standard ML in at Cambridge University and really didn't like it partly because the examples were all theoretical computer science and I am a physicist and because its implementations sucked when I complained they gave me kLOC of ML compiler source that didn't even compile and told me to fix it myself. I picked OCaml up after my PhD and found it to be far more practically viable. OCaml obviously has lots of features that Haskell and Erlang lack.

Moreover, those features turn out to be essential in practice. Two years later, OCaml doesn't seem more popular. Four years later, OCaml doesn't seem more popular. J D J D 2, 23 23 silver badges 17 17 bronze badges. I think that if OCaml were more popular, more people would find it normal to make an effort to learn it. Giorgio " I think that if OCaml were more popular, more people would find it normal to make an effort to learn it".

I think more people learn Python and Ruby because they're comparatively easy to learn. OCaml is not popular and therefore people do not think it is worthwhile learning it. But I have never ever seen anyone use OCaml. I heard people talking about maybe learning it, but I've never seen anyone use it. Searching on scicomp. Your advocacy for this use of ML did Then you can gradually on board the java developers to FP paradigms, without hurting their productivity in the short term.

After a year or so, you can go all in on cats or zio, all within the same language. My favorite thing about the Scala community is that it attracts architects with deep expertise in building highly available systems, high throughput systems, and scalable systems.

I also see less NIH syndrome in Scala shops. The Scala shops usually want to use the best tools and libraries that they can find, rather than use tools implemented exclusively in Scala.

If I wanted to find people who knew how to use Kafka, Cockroachdb, or some other best of breed tool, I would put Scala in my job advertisement. My general preferences are: 1. Haskell, 2. OCaml, 3. In , it feels like the jvm is just an awkward historical leftover that makes containerizing more complex, so I try to avoid scala and clojure when possible.

Why are you considering akka? If so, I would probably attempt zio or haskell with a distributed cache, rather than akka. One issue with integrating Scala with Java libraries is the awkward issue of Null in Java.

The presence of Null in the Java ecosystem is a huge negative in general — looking from the outside. I wonder if it was a practical concern when you programmed in Scala 2 though. Regarding akka, my use case is for a system that involves a lot of messages. OCaml BTW is excellent here — though the language is less expressive and the ecosystem not as rich as Haskell, the runtime is totally rock solid.

I was further piqued by your by personal ranking of Haskell ahead of OCaml. You spent so much of time writing type heavy code to get good safety but then your code has a space leak and you need to track it down. That does not seem like a good tradeoff for me — gaining significant safety due to types but then promptly throwing all those safety guarantees away due to laziness because it can cause space leaks.

I used this sometimes - Scala Standard Library 2. You have to wrap each java method with transformations like this. Why should I use OCaml? Is OCaml suitable for the task? Does OCaml has the same problem as Scala? To learn Scala looks like I need to learn 10 languages. OCaml is a language that promotes developer productivity. You can smash together stuff to get the job done and refactor later because of the type system Makes some really solid tradeoffs from an engineering point of view, e.

OCaml is the language and compiler to native or bytecode. ReScript is two things: A new alternative syntax that looks similar to Reason with more changes.

It supports less OCaml language features and can only be used when compiling to JS. A rebranding of the Bucklescript compiler.

It can compile from ReScript syntax. Like Bucklescript, it is still on an older OCaml compiler version.



0コメント

  • 1000 / 1000