Live data from Hacker News

OCaml as my primary language

xvw.lol

101–110 of 296 posts

Re: OCaml as my primary language

#101
post #97

Earlier quoted context omitted.

A first-order function type is already exponential. A sum type has as many possible values as the sum of its cases. E.g. `A of bool | B of bool` has 2+2=4 values. Similarly for product types and exponential types. E.g. the type bool -> bool has 2^2=4 values (id, not, const true, const false) if you don't think about side effects.

> bool -> bool has 2^2=4 values Not the best example since 2*2=4 also. How about this bit of Haskell: f :: Bool -> Maybe Bool That's 3 ^ 2 = 9, right? f False = Nothing f False = Just True f False = Just False f True = Nothing f True = Just True f True = Just False Those are 6. What would be the other 3? or should it actually be a*b=6? EDIT: Nevermind, I counted wrong. Here are the 9: f x = case x of True -> Nothing…

Good point, well there's Ordering type built-in in Haskell (LT | EQ | GT). Ordering -> bool has 2^3=8 values (const true, const false, == LT, == EQ, == GT, is_lte, is_gte, ne)

EDIT: now you see why I used the smallest type possible to make my point. Exponentials get big FAST (duh).

Re: OCaml as my primary language

#102
post #97

Earlier quoted context omitted.

A first-order function type is already exponential. A sum type has as many possible values as the sum of its cases. E.g. `A of bool | B of bool` has 2+2=4 values. Similarly for product types and exponential types. E.g. the type bool -> bool has 2^2=4 values (id, not, const true, const false) if you don't think about side effects.

> bool -> bool has 2^2=4 values Not the best example since 2*2=4 also. How about this bit of Haskell: f :: Bool -> Maybe Bool That's 3 ^ 2 = 9, right? f False = Nothing f False = Just True f False = Just False f True = Nothing f True = Just True f True = Just False Those are 6. What would be the other 3? or should it actually be a*b=6? EDIT: Nevermind, I counted wrong. Here are the 9: f x = case x of True -> Nothing…

You didn't list all functions, just input-output pairs. Each function is a map from every possible input to an output:

f1 False = Nothing, f1 True = Nothing

f2 False = Nothing, f2 True = Just True

...

This gives the correct 3^2 = 9 functions.

Re: OCaml as my primary language

#103
post #55

Earlier quoted context omitted.

I'd say that Google strives to have a reasonably short list of languages approved for production-touching code. Rust can replace / complement C++, while OCaml cannot (it could replace Go instead... fat chance!). So I suspect that the team picked Rust because it was the only blessed language with ADTs, not because they won't like something with faster compile times. No way OCaml could have stolen the Rust's thunder: w…

Wouldn’t Kotlin be a more reasonable choice in that case? It has ADTs and a lot of the same niceties of Rust.

Garbage collector in Kotlin makes it a no go for C or C++ displacement.

Re: OCaml as my primary language

#104
post #55

Earlier quoted context omitted.

I'd say that Google strives to have a reasonably short list of languages approved for production-touching code. Rust can replace / complement C++, while OCaml cannot (it could replace Go instead... fat chance!). So I suspect that the team picked Rust because it was the only blessed language with ADTs, not because they won't like something with faster compile times. No way OCaml could have stolen the Rust's thunder: w…

Wouldn’t Kotlin be a more reasonable choice in that case? It has ADTs and a lot of the same niceties of Rust.

I'm inclined to think that the Python -> Rust was only for some odds and ends. I know the biggest recipient of Rust trainings was the Android platform team at first, which I think also used a lot of C++.

Kotlin is definitely available at Google, but when talking about sym types et al it's not nearly as nice to use as Rust / OCaml.

Re: OCaml as my primary language

#105
post #99

Earlier quoted context omitted.

Unless you reach an unsound part of the type system I don't see how. Could you provide an example?

- You can use GADTs ( https://ocaml.org/manual/5.2/gadts-tutorial.html ) and indexes to give a concrete type to every constructors: ```ocaml type _ treated_as = | Int : int -> int treated_as | Float : float -> float treated_as let f (Int x) = x + 1 (* val f : int treated_as -> int *) ``` - You can use the structurale nature of polymorphic variants ( https://ocaml.org/manual/5.1/polyvariant.html ) ```ocaml let f = fun…

Oh if you use those features to express what "sum type as subtyping" can, it sure gets confusing. But it's not those things that I want to express that are hard to reason about, the confusing part is the additions to the HM type system.

A meta point: it seems to me that a lot of commenters in my thread don't know that vanilla HM cannot express subtypes. This allows the type system to "run backwards" and you have full type inference without any type annotations. One can call it a good tradeoff but it IS a tradeoff.

Re: OCaml as my primary language

#106
post #71

I'm sure there's merit to the language, but the syntax seems absolutely alien to me. Some attempt to look like verbose imperative code, a bunch of semicolons, and for some strange reason, hate of parenthesis. Real life sample: let print_expr exp = (* Local function definitions *) let open_paren prec op_prec = if prec > op_prec then print_string "(" in let close_paren prec op_prec = if prec > op_prec then print_string…

`let` defines a value. Some values are "plain old values", some are functions. The syntax is `let = in ;;` where `expression` can also have `let` bindings. So you can have let one = 1 in let two = 2 in let three = one + two in print_endline (string_of_int three);;

The way I always think about it is in terms of scope. With:

  let x = v in expr
`x` is now available for use in `expr`

In essence, an OCaml program is a giant recursive expression, because `expr` can have its own set of let definitions.

In the REPL, this is where the double semicolons come in, as a sort of hint to continue processing after the expression.

Re: OCaml as my primary language

#107
post #72

Earlier quoted context omitted.

OCaml also needed the brief but bright ReasonML moment to add/fix/improve some of the syntax IIRC and work on user-friendly error messages. But this should've definitely happened much much earlier than it did.

I would say ReasonML also needed more follow-through. It seems like the OCaml community hasn't really rallied behind it.

Maybe it's good it died? Now we have moonbit lang.

Re: OCaml as my primary language

#108
post #23

I migrated from OCaml to Rust around 2020, haven't looked back. Although Rust is quite a lot less elegant and has some unpleasant deficiencies (lambdas, closures, currying)... and I end up having to close one one eye sometimes and clone some large data-structure to make my life easier... But regardless, its huge ecosystem and great tooling allows me to build things comparatively so easily, that OCaml has no chance. A…

Were you using the ocamlopt compiler? By default, ocaml runs in a VM, but few people figure that out because it is not screaming its name all the time like a pokemon (looking at you JVM/CLR). But ocaml can be compiled to machine code with significant performance improvements.

Re: OCaml as my primary language

#109

I saw a talk by someone from Google about their experiences using Rust in the Android team. Two points stuck out: they migrated many projects from Python, so performance can't have been that much of a concern, and in their surveys the features people liked most were basics like pattern matching and ADTs. My conclusion is that for a lot of tasks the benefit from Rust came from ML cicra 1990, not lifetimes etc. I feel…

> I feel if OCaml had got its act together around about 2010 with multicore and a few other annoyances[1] it could have been Rust.

Arguably, that could have been Scala and for a while it seemed like it would be Scala but then it kind of just... didn't.

I suspect some of that was that the programming style of some high profile Scala packages really alienated people by pushing the type system and operator overloading much farther than necessary.

Re: OCaml as my primary language

#110
post #99

Earlier quoted context omitted.

- You can use GADTs ( https://ocaml.org/manual/5.2/gadts-tutorial.html ) and indexes to give a concrete type to every constructors: ```ocaml type _ treated_as = | Int : int -> int treated_as | Float : float -> float treated_as let f (Int x) = x + 1 (* val f : int treated_as -> int *) ``` - You can use the structurale nature of polymorphic variants ( https://ocaml.org/manual/5.1/polyvariant.html ) ```ocaml let f = fun…

Oh if you use those features to express what "sum type as subtyping" can, it sure gets confusing. But it's not those things that I want to express that are hard to reason about, the confusing part is the additions to the HM type system. A meta point: it seems to me that a lot of commenters in my thread don't know that vanilla HM cannot express subtypes. This allows the type system to "run backwards" and you have full…

Yes and my point was, when you want what you present in the first comment, quoting my post, you have tools for that, available in OCaml. But there is cases, when you do not want to treat each branch of your constructors "as a type", when the encoding of visitors is just rough. This is why I think it is nice to have sum type, to complete product type. So i am not sure why we are arguing :)
Post reply on HN