Questions tagged [hindley-milner]

In type theory, Hindley–Milner (HM) is a classical type inference method with parametric polymorphism for the lambda calculus.

In , Hindley–Milner (HM) is a classical type method with for the lambda calculus.

One property that makes the Hindley-Milner type theory important is its completeness and its ability to deduce the most general type of a given source without the need of any type annotations or other hints. HM is a fast algorithm that can compute a type almost in linear time with respect to the size of the source, which makes it of practical use for the types of large programs. HM is used for several functional programming languages. It was first implemented as part of the type system of the programming language . Since then, HM has been extended in various ways, most notably by constrained types as used in , which it has a strong association with.

The original paper

A Theory of Type Polymorphism in Programming

Languages implementing Hindley-Milner

See also

84 questions
2
votes
1 answer

`Let` inference in Hindley-Milner

I am trying to teach myself Hindley-Milner type inference by implementing Algorithm W in the language I usually use, Clojure. I am running into an issue with let inference, and I'm not sure if I'm doing something wrong, or if the result I'm…
grandinero
  • 1,155
  • 11
  • 18
2
votes
1 answer

How to derive a procedure's HM type based on its implementation?

Given these two procedures (written in JavaScript) … // comp :: (b -> c) -> (a -> b) -> (a -> c) const comp = f=> g=> x=> f (g (x)) // comp2 :: (c -> d) -> (a -> b -> c) -> (a -> b -> d) const comp2 = comp (comp) (comp) My question is how to…
Mulan
  • 129,518
  • 31
  • 228
  • 259
2
votes
2 answers

Hindley-Milner generalization gone bad?

Consider the following program (in Haskell, but could be any HM-inferred language): x = [] y = x!!0 Using HM (or by running the compiler), we infer: x :: forall t. [t] y :: forall a. a I understand how this happens, playing by the usual…
sinelaw
  • 16,205
  • 3
  • 49
  • 80
1
vote
1 answer

How to comprehend Algorithm W in Hindley–Milner type system?

I am studying the algorithm W. From my understand, algorithm W takes (Γ,expr) as input ,where Γ is the context, and expr is the expression. The output is a substitution σ. Then I can use the substitution σ to take another (Γ,expr) as σ(Γ,expr). What…
Joe
  • 61
  • 9
1
vote
1 answer

Can a type statically guarantee that a function to pairs only partially depends on its input?

Consider the type of a function from a's to pairs of b's and c's, a -> (b, c). (I'll use Haskell notation for types and functions, but this isn't a question about Haskell per se.) There are many such functions, including those where both, one, or…
SEC
  • 799
  • 4
  • 16
1
vote
2 answers

How to represent functions with multiple arguments in Hindley-Milner?

I'm reading a functional programming tutorial called Professor Frisby's Mostly Adequate Guide to Functional Programming, the author gives an introduction to Hindley-Milner and several examples about it, one of them being: // reduce :: (b -> a -> b)…
Searene
  • 25,920
  • 39
  • 129
  • 186
1
vote
0 answers

What is the best algorithm for Hindley Milner type inference when one wants to optimize for error messages

I want to implement Hindley-Milner type inference but as a non-academic person that doesn't know type theory at all, I'm getting a bit overwhelmed by all the different algorithms and their properties, the dependencies of papers on papers and all the…
Stefan Wullems
  • 743
  • 1
  • 7
  • 20
1
vote
2 answers

How to interpret this Ramda signature?

Could someone explain how to understand this notation: ((a, b) → a) → a → [b] → a See: https://ramdajs.com/docs/#reduce
Maciej Miklas
  • 3,305
  • 4
  • 27
  • 52
1
vote
1 answer

Unification of applicators with different arity through substitution

I'm able to unify the following terms: foo :: (a -> b -> c) -> a -> b -> c bar :: (a' -> b') -> a' -> b' foo bar a ~ (a' -> b') b ~ a' c ~ b' (a' -> b') -> a' -> b' But I'm stuck applying the correct rules for the following unification, because…
user5536315
1
vote
2 answers

What's the F# type inference approach to generics?

I'm trying to understand rules around type inference as I'd like to incorporate it into my own language, and in that spirit I've been playing around with F#'s type inference, and the following struck me as odd. This compiles, and id is 'a -> 'a,…
Jeff
  • 12,085
  • 12
  • 82
  • 152
1
vote
1 answer

Extend the W algorithm to containers

I would like to extend the W algorithm to the inference of tuples and lists in F#, a priori, there are only two rules to add, which I did, however, the result is partially bad. Indeed, if I test a code like these: test = (8, "Hello", 0.3) -- test…
Foxy
  • 980
  • 8
  • 17
1
vote
2 answers

Inferred type of an infinitely recursive function

For a loop like below: let rec loop () = loop () the signature according to try.ocamlpro.com is: val loop : unit -> 'a = Why is this the case? loop() never stops calling itself so shouldn't it return anything?
Kevin Wu
  • 1,357
  • 1
  • 15
  • 34
1
vote
1 answer

How to derive the type of an applicator applied to the identity function

I want to derive the type of the following contrived applicator applied to the identity function. To achieve this I probably have to unify the type portion of the first argument (a -> [b]) with the type of id: ap :: (a -> [b]) -> a -> [b] id :: a ->…
user6445533
1
vote
2 answers

Functional JavaScript: What is the Hindley-Milner Type Signature of Compose?

Is the following attempt at the Hindley-Milner Type Signature for the compose function correct? // compose :: (f -> [f]) -> (f -> f -> f) -> [f] -> f const compose = (...fns) => fns.reduce((f,g) => (...args) => f(g(...args)));
MFave
  • 1,044
  • 2
  • 8
  • 19
1
vote
1 answer

Type information in Abstract Syntax Trees

What type information exists in an abstract syntax tree? How are ASTs used for type inferencing? I don't understand how type input and output can be derived given an AST when none of the nodes indicate the concrete types. Are the types inferred from…
Soubriquet
  • 3,100
  • 10
  • 37
  • 52