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
10
votes
1 answer

What are some types and/or terms in system-f that cannot be expressed in Hindley Milner

I remember reading somewhere that Hindley Milner was a restriction on system-f. If that is the case, could someone please provide me with some terms that can be typed in system-f but not in HM.
user181351
10
votes
4 answers

Limit a number to a range (Haskell)

I am exposing a function which takes two parameters, one is a minimum bound and the other is a maximum bound. How can I ensure, using types, that for example the minimum bound is not greater than the maximum bound? I want to avoid creating a smart…
10
votes
1 answer

Infer type of a string containing a Haskell expression

I need a (quick and dirty) way to get some representation of the type of a Haskell expression that is given as a string. I currently see 3 options: Use GHC API -- however, the documentation loses me pretty quickly. Use some other type inference…
xcvii
  • 450
  • 3
  • 17
9
votes
1 answer

runST with Hindley-Milner type system

If I understand the ST monad in Haskell correctly, runST uses rank-2 types in a clever way to ensure that a computation does not reference any other thread when escaping the monad. I have a toy language with a Hindley-Milner type system, and my…
max
  • 1,048
  • 10
  • 20
9
votes
0 answers

Representing polymorphism with unification-fd

I'd like to use the unification-fd package to implement a simple typechecker for a Hindley-Milner type system. This requires the representation of polymorphic ("forall") types. What's the best way of representing these types? The variables provided…
Cactus
  • 27,075
  • 9
  • 69
  • 149
9
votes
2 answers

Example of type in System F that is not available in Hindley Milner type inference

Under 'What is Hindley Milner' it states: Hindley-Milner is a restriction of System F, which allows more types but which requires annotations by the programmer. My question is, What is an example of a type available in System F, that is not…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
9
votes
1 answer

Determine the effect of a function by its type

One of the interesting properties of Haskell's type system (*) is that sometimes you can tell exactly what the function does based only on its type signature (assuming there's no unsafe IO dark magic invloved). For example, any function with the…
Benesh
  • 3,398
  • 1
  • 18
  • 38
9
votes
1 answer

Inferring recursive expressions using Hindley Milner & constraints

I am trying to infer the type of the following expression: let rec fix f = f (fix f) which should be given the type (a -> a) -> a After using the bottom up algorithm (described in generalizing hindley-milner type inference algorithms) with the…
user181351
8
votes
1 answer

Hindley Milner Type Inference in F#

Can somebody explain step by step type inference in following F# program: let rec sumList lst = match lst with | [] -> 0 | hd :: tl -> hd + sumList tl I specifically want to see step by step how process of unification in Hindley Milner…
hrishikeshp19
  • 8,838
  • 26
  • 78
  • 141
8
votes
1 answer

Characterizing the type of functions that can accept `()` as input (without monomorphizing)

Here are a few simple functions: f1 :: () -> () f1 () = () f2 :: a -> a f2 a = a f3 :: a -> (a, a) f3 a = (a, a) f4 :: (a, b) -> a f4 (a, b) = a All of f1, f2, and f3 are able to accept () as an input. On the other hand, of course, f4 can't…
SEC
  • 799
  • 4
  • 16
8
votes
2 answers

Can we have type variables in constructor position in the Hindley Milner type system?

In Haskell we can write the following data type: data Fix f = Fix { unFix :: f (Fix f) } The type variable f has the kind * -> * (i.e. it is an unknown type constructor). Hence, Fix has the kind (* -> *) -> *. I was wondering whether Fix was a…
Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
8
votes
1 answer

Why are type-safe relational operations so difficult?

I was trying to code a relational problem in Haskell, when I had to find out that doing this in a type safe manner is far from obvious. E.g. a humble select 1,a,b, from T already raises a number of questions: what is the type of this…
Martin Drautzburg
  • 5,143
  • 1
  • 27
  • 39
7
votes
2 answers

Simply typed lambda calculus vs Hindley-Milner type system

I have recently been learning about λ-calculus. I understood the difference between untyped and typed λ-calculus. But, I'm not much clear about the distinction between the Hindley-Milner type system and the typed λ-calculus. Is it about parametric…
7
votes
2 answers

Haskell type checking and determinism

According to the Haskell 2010 language report, its type checker is based on Hindley-Milner. So consider a function f of this type, f :: forall a. [a] -> Int It could be the length function for instance. According to Hindley-Milner, f [] type checks…
V. Semeria
  • 3,128
  • 1
  • 10
  • 25
7
votes
2 answers

Can I verify whether a given function type signature has a potential implementation?

In case of explicit type annotations Haskell checks whether the inferred type is at least as polymorphic as its signature, or in other words, whether the inferred type is a subtype of the explicit one. Hence, the following functions are…
user6445533