When comparing OCaml vs Swift, the Slant community recommends OCaml for most people. In the question“What are the best (productivity-enhancing, well-designed, and concise, rather than just popular or time-tested) programming languages?” OCaml is ranked 14th while Swift is ranked 30th. The most important reason people chose OCaml is:
Functional programming is based on the lambda calculus. OCaml is in its functional parts almost pure lambda calculus, in a very practical manner: useful for many daily programming tasks. The acitve development makes improvements to the type system like generalized algebraic data types (GADT) or polymorphic variants, so when learning this language you get at once a down to earth usable compiler and advanced abstraction features.
Specs
Ranked in these QuestionsQuestion Ranking
Pros
Pro Actively-developed functional programming language at the forefront of research
Functional programming is based on the lambda calculus. OCaml is in its functional parts almost pure lambda calculus, in a very practical manner: useful for many daily programming tasks. The acitve development makes improvements to the type system like generalized algebraic data types (GADT) or polymorphic variants, so when learning this language you get at once a down to earth usable compiler and advanced abstraction features.
Pro Encourages functional style
It steers you towards a functional style, but doesn't bother you with purity and "monads everywhere" like other languages, such as Haskell.
Pro No windows!
Strong focus on *nix systems, lacking native support for MS Windows
Lacks native support for Windows systems.
Pro Sophisticated and easy-to-use package manager
OPAM is a package manager for OCaml, which is really easy to use, just like npm. It creates a .opam folder in home directory.
The documentation is great as well, and you can switch between multiple versions of OCaml for each project. You can also package your project and publish it on OPAM repositories, even if the dependencies do not exists on OPAM.
Pro One of the best for writing compilers
OCaml is compiled to native binary, so it's amazingly fast. Being a member of ML-family languages, it has expressive syntax for trees, and has great LLVM support.
Pro Stable syntax
The syntax is consistent, some syntaxic sugar but at a reasonable level, so reading code of others isn't too much confusing.
Pro Strong editor integration
The merlin
editor tool provides all you need to develop OCaml in your favourite editor.
Pro Modern syntax
Pro Swift is closer to other platforms
Apple’s modern programming language is easier to understand for non-iOS developers and minimizes time for additional explanations and clarifications. Moreover, Swift can be used as a script language. It is an interesting solution for the iOS community to unify writing of build scripts. At the time being iOS developers are split up in regard to this activity. Some of them write build scripts in Bash, others use Ruby, Python, etc. Swift gives an amazing opportunity to be applied to all iOS programming needs.
More details can be found here https://mlsdev.com/blog/51-7-advantages-of-using-swift-over-objective-c
Pro Works with Apple's Cocoa and Cocoa Touch frameworks
Pro Can be used as a Just-In-Time language
Pro Inherent parallelism
Pro Low memory footprint due to reference counting
Pro Backed by Apple
Pro Performance speed comparable to native C
Pro Swift has some clever tricks up its sleeve
Due to having elements of a functional programming language. Things like 'map' and 'filter' for example.
Pro Uses LLVM compiler and Obj-C runtime allowing C, Objective-C, Objective-C++ and Swift code to run side by side within a single program
Cons
Con Strong focus on *nix systems, lacking native support for MS Windows
Lacks native support for Windows systems.
Con Swift is a moving target
They've released 1.2 so far, and 2.0 is coming soon. Every small update brings adjustments to paradigms (such as how to do type casting) that can be a little frustrating to absorb. Objective C was also constantly updating, however, but not at the same rate these days.