3 ms·
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 ty
by kragen 5y ago
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.
- legobmw99 5y agoOCaml 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