3 ms·
I would correct a couple of things here. > The language is on par with F#, It's on par in some ways, and fairly they're different in other ways. E.g. F# has r
by yawaramin 6y ago
I would correct a couple of things here.
> The language is on par with F#,
It's on par in some ways, and fairly they're different in other ways. E.g. F# has reified generics while OCaml erases all types at runtime.
> notably less expressive than Scala.
Personally I find it super difficult to express a lot of things in Scala that I can bang out in a few simple lines of OCaml. One of the simplest possible things for an FP language, try writing a sum type that type-checks properly when you put it in a list. Scala:
scala> sealed trait PaymentMethod
object PaymentMethod {
case object Cash extends PaymentMethod
case class CreditCard(name: String, number: String, expiry: String) extends PaymentMethod
}
scala> Seq(PaymentMethod.Cash, PaymentMethod.CreditCard(name = "Bob", number = "1111111111111111", expiry = "10/21"))
res0: Seq[Product with PaymentMethod with java.io.Serializable] = ...
OCaml:
# module PaymentMethod = struct
type t =
| Cash
| CreditCard of { name : string; number : string; expiry : string }
end;;
# [Cash; PaymentMethod.CreditCard { name = "Bob"; number = "1111111111111111"; expiry = "10/21" }];;
- : PaymentMethod.t list = ...
- smabie 6y agoThis is true, but Scala 3 solves this with enums. And with the new optional brace syntax, Scala is starting to look more like OCaml every day. In Scala 3: enum PaymentMethod case Cash case CreditCard(name: String, number: String, expiry: String) Seq(Cash, CreditCard("Bob", "1111111111111111", "10/21"))
- yawaramin 6y agoThat's unfortunately another one of Scala's cons, there will be a large breaking change in a few years and the ecosystem will be split again.
- pjmlp 6y agoJava is slowly getting good enough for those of us that have to deal with mob development while wanting to enjoy a little bit of FP programming in the process, if the optional brace syntax goes through, that might that be the final straw for those that haven't yet moved back to Java or started to find new loves like Kotlin.