News for hackers. Stuff that matters.
Re:What I wish I knew when learning OCaml (2018) by kragen on Tuesday May 03, 2022 @06:42AM (#31246739)
Hey, thanks for that "assert false" trick! I never knew that!

I don't know much about type theory but I did eventually manage to learn to interpret OCaml's type errors well enough to get things to compile. It still feels like driving a car by scraping it along a highway guardrail but it's often better than testing. I have to write twice as much code as in Python, it takes me longer to get it to run, and I still can't call it from C or Lua, but it runs twenty times as fast as Python and the process of thinking through the types helps me a lot to write code that works.

I keep hoping I'll internalize the type system enough that my programs run the first time they way they do in Python, but it hasn't happened yet.

I still often write a prototype in Python, though.

Re:What I wish I knew when learning OCaml (2018) by legobmw99 on Tuesday May 03, 2022 @09:00AM (#31247725)
OCaml also has a built in function failwith: string -> ‘a, so you can print an error in those cases. If it’s a code path you ever think will execute, failwith “some error here” is probably better than assert false