Daniel @webcloud.se · Jan 15

Coming from a TypeScript background, I think this will take a while to get used to: In OCaml, the compiler type error "bubbles" up to the top of the call stack. TypeScript does the opposite. My feeling is the latter helps me find problems faster Any thoughts or feelings on this? #OCaml #TypeScript

18 likes 4 replies

?

Replies

Chris Armstrong · Jan 17

Tangential, but OCaml’s type inference works from the inside-out, rather than outside-in as it (typically) runs in TS. The innermost thing which can be inferred informs the types up to the function level, rather than parameters dictating types into the function declaration and meeting halfway.

Hyeseong Kim · Jan 16

The signature for the TypeScript one with the same capability is: function countZero<T>(grid: T[][]): number; If you're familiar with generic programming in TypeScript, you might think it is automatically applied in OCaml.

Gabriel Nordeborn · Jan 16

They're not equal snippets though - you're annotating the arg in TS but not in OCaml. So in OCaml it's inferred to be whatever you use it as (comparing to an int, so int). If you annotate in OCaml (string list list I think, can never remember the order of type args) it should error in the same way