I kept writing Hindley-Milner signatures in my comments, so I made them type-check
A few years ago I worked my way through Professor Frisby's Mostly Adequate Guide to Functional Programming . Chapter 7, "Hindley-Milner and Me", has signatures in comments like these: // strLength :: String -> Number const strLength = s => s . length ; // join :: String -> [String] -> String const join = curry ( ( what , xs ) => xs . join ( what ) ) ; // replace :: Regex -> String -> String ->…
In the article "HinMil: Type-checking JavaScript with Hindley-Milner signatures," the author describes a language server and CLI that type-checks JavaScript against comments containing signatures. The idea stems from the functional programming guide "Mostly Adequate Guide to Functional Programming" by Professor Frisby, which used comments to document functions, specifying the input, output, and their relationship.
The author found this helpful, as these signatures only serve as comments and are not checked by the system. The author developed HinMil, which type-checks JavaScript based on the signatures in the comments, allowing for a functional style without the need for a compiler. The article notes that while functional programming in JavaScript was popular around 2015-2017, it has largely been absorbed into everyday JavaScript development, with concepts like map, filter, and reduce replacing loops, and functional style being used in React and Redux.
HinMil caters to developers who already write JavaScript using this style, or have existing JavaScript codebases they don't want to convert to TypeScript. The signatures in HinMil are a dialect of Hindley-Milner, incorporating JavaScript-specific elements such as curried functions, objects as records, JavaScript types (null, undefined, any), and type classes without instances.
The author provides an example of how HinMil modifies a piece of code, highlighting the signatures, displaying errors, and updating types as the user types.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to