Live data from Hacker News

OCaml Programming: Correct and Efficient and Beautiful

cs3110.github.io

231–240 of 251 posts

Re: OCaml Programming: Correct and Efficient and Beautiful

#231
post #214

Earlier quoted context omitted.

I program primarily in (untyped) Python (which, I get is technically strongly typed but people don't think in technical terms) these days, and I almost never experience type errors. I guess I could attribute this to a couple things: - I'm very specific about when I use None - I'm a big fan of named function arguments - I like to think my naming of things is pretty good, as are my conventions for parameters - I try to…

Python is OK for throwaway code, but I've mostly seen it used for big systems that people (for whatever reason) didn't think were important enough to write in a real language. The people with that opinion don't share your degree of rigor. I usually avoid bugs in python code by rewriting in bash (at 1-10% the size of the original python, since bash's error handling can be set to "always do the right thing" with "set e…

Yeah I love Python for quick work and prototyping, and it's great for small web services and as a DSL for data analysis. I suppose I could also envision it as a backend language for a fleet of microservices too.

I think Python gets bailed out a lot because those things turn out to be a lot of programming these days. The people who have a beef w/ Python are those who've worked with it on large, old codebases. This is a tough job for any language though like, raise your hand if you've ever worked on a large, old codebase in C++ or Java that you liked.

Usually when people push microservices I'm quick with Conway's law, saying "this is a tech solution to an organizational problem that won't actually make a difference", and I think I'm right about that. But I think I've been ignoring that a really nice thing about microservices for engineers is you can keep using languages like Python on small codebases, and at least mentally and emotionally avoid the feeling of working on a huge monolith. That counts for something.

Re: OCaml Programming: Correct and Efficient and Beautiful

#232

Earlier quoted context omitted.

With OCaml type system permanently burned in my mind, I parse that error message as "there is an ` _ -> Result_set.t ` arrow type which is not compatible with type `Result_set.t`". Do you think that the issue is that the arrow `->` is too hard to spot?

It might help to make the difference more obvious by also showing the parts which unify properly, or introduce alias variables for complex type expressions (for instance "(int * float array) list as 'a") to move away some of the noise in the error.

No post body was provided.

Re: OCaml Programming: Correct and Efficient and Beautiful

#233
post #223

Earlier quoted context omitted.

I think the big win is actually immutable data and pure functions. It just so happens that strong typing tends to come along with these things (e.g. Haskell, OCaml)

Clojure is the big outlier

And Erlang / Elixir. These are also some of the most widely used FP languages in delivering real world software.

Re: OCaml Programming: Correct and Efficient and Beautiful

#234

Earlier quoted context omitted.

Forgive my ignorance, I'd would like an example of the "functional" (hehe) benefits of automatic currying

Partial application and function composition are the meat-and-potatoes of functional programming. Automatic currying is syntactic sugar that can make these two easier and clearer as it gets rid of a bunch of named arguments and lambdas. For example, I can write: foo a b c = a * b + c I can then apply this partially like this (foo2 just takes argument c): foo2 = foo 10 20 and compose it with other functions, for examp…

[deleted]

Re: OCaml Programming: Correct and Efficient and Beautiful

#235
post #27

I found my experience trying to work with a large OCaml base a nightmare — when signatures changed in an unstable dependency (e.g. function argument removed and nested inside another), the errors spat out by the typechecker were utterly incomphrehensible. This was largely due to automatic currying in OCaml — if I have a function call "some_function arg1 arg2" and "some_function" adds a third argument, that call becom…

Forgive my ignorance, I'd would like an example of the "functional" (hehe) benefits of automatic currying

I find this phrase "Automatic Currying" that people are using in this thread to be very strange.

It implies that `(add 3)` is being magically converted into `(\x -> (add 3 x))` by some fancy front-end feature.

But no, `add` is just a function that returns a function.

This pattern is core to the entire paradigm of functional programming, all the way down to the lambda calculus.

All functional programming languages are essentially just fancy syntax around lambda calculus. They have different implementation strategies (strict vs lazy), different type systems, and they have been extended with different primitives (floats, operations on floats, etc).

But at their core, they are all just lambda calculus.

In the lambda calculus, there is ONLY functions, and all functions take one argument. There are no tuples. So, multiple arguments are implemented with the pattern in question. For example:

mul = (λx. λy. λz. x(yz))

Re: OCaml Programming: Correct and Efficient and Beautiful

#236
post #150
post #45

Earlier quoted context omitted.

yes, that would be a straightforward error message! But I got the error message Error: This expression has type ((locl_ty * Tast.pos * ('ex, 'fb, 'en) Aast.expr_) list -> Result_set.t) list but an expression was expected of type Result_set.t list Type (locl_ty * Tast.pos * ('ex, 'fb, 'en) Aast.expr_) list -> Result_set.t is not compatible with type Result_set.t Which is not half as readable.

Stockholm syndrome arrives quite quick in this case, as you become accustomed to this form as meaning "you're missing an arg" I agree the first 6 months of this is mind-numbingly frustrating.

> Stockholm syndrome

Is a lie fabricated to deflect criticism of the person who coined the term via abusive ad hominem of the critic.

Surprisingly, that tends to predict the quality of arguments invoking Stockholm syndrome pretty well, too.

Re: OCaml Programming: Correct and Efficient and Beautiful

#237
post #112

Earlier quoted context omitted.

I used StandardML at university in the early 2000s, and I appreciate that OCaml is an older language that heavily influenced the design of Rust. Given that history, it’s instructive to note the sorts of things (like auto-currying) that Rust did not inherit.

Rust is a different language with a different audience. If a functional language is presented today that does not automatically curry calls, I have no interest. Just because the tool does not work for you does not mean there's a defect in the design.

That's weird, I really don't see the interest of 'automatic currying', optional/volontary currying? Sure that's interesting.

But automatic I don't see the point, it's like automatic conversion in C: not the good default IMHO.

Re: OCaml Programming: Correct and Efficient and Beautiful

#238
post #213

Earlier quoted context omitted.

I learned SML/NJ and OCaml around the same time and for some reason I found SML more pleasant. I particularly liked the SML "Basis" library, it felt really well designed to me. Still, I'd pick either over Scala. Superior compilation times, cleaner syntax, less complex. Haskell also just feels excessively clever. I had hoped Rust would be "OCaml but for systems programming" and it sort of is, -- but the borrow checker…

For me, the borrow checked removes a lot of mental overhead. It finds all sorts of subtle concurrency bugs in my code.

Depends on your starting point. More overhead than GC, most of the time, so much less than C/C++

Re: OCaml Programming: Correct and Efficient and Beautiful

#239
post #218

Earlier quoted context omitted.

> BP is PP plus what's required to make it more than a toy And in fact OCaml does have BP, as was explained earlier, just with a heavier syntax. > effective inability to use point-free style OK but point-free style is not an end in itself, it's just a means to an end (clean code), and there's certainly no universal agreement that it's the best means...explicit style is almost always easier to understand for a wide as…

> just with a heavier syntax. Ok, I'm glad we agree on that. > I can see how writing Eta reduction is one example, but a great deal of code is cleanly expressed as e.g. vecLen = sum . map (^2) And ocaml's type system is not capable of handling this gracefully. Very unfortunate!

?

    let vec_len vec = vec |> map (fun x -> x ** 2.) |> sum
Or even

    let square x = x ** 2.
    let vec_len vec = vec |> map square |> sum
Honestly, if code like this is the biggest nitpick, I have a hard time taking the argument seriously.

Re: OCaml Programming: Correct and Efficient and Beautiful

#240

Earlier quoted context omitted.

I can assure you I will and in fact have found plenty of takers for my job postings with a niche language. You just need to word the postings appropriately and be willing to teach people what they don't know.

You just need to word the postings appropriately and be willing to teach people what they don't know. OK, I'll grant that if you have that "magic skill" then you can in fact recruit developers for niche languages. Most companies don't, as we know, and frankly it's amazing to me how incoherent their communications are throughout their so-called hiring process.

If having sensible hiring practices is a 'magic skill', then I guess call me Harry Houdini!
Post reply on HN