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
4
votes
2 answers

Bottom up Hindley-Milner type inference: Applying a substitution to an implicit constraint

I am trying to implement the 'Bottom up' type inference algorithm which can be found in Generalizing Hindley-Milner Type Inference Algorithms Page 6 explains how an implicit constraint is t1 should be an instance of the type scheme that is…
user181351
3
votes
1 answer

How can I infer types for recursive functions?

I'm trying to implement language with type inference based on Hindley-Milner algorithm. But I don't know how to infer types for recursive functions: f = g g = f Here I must generate and solve constraints for f and g together because if I will do it…
3
votes
1 answer

Is there something infeasible about statically-typing actor models of interprocess communication?

So I only recently encountered akka outside of a toy capacity, and I can't help notice that it and OTP share dynamic typing despite scala's general preference for static types. I started digging around a little bit, and came across this Wadler paper…
jcc333
  • 759
  • 5
  • 15
3
votes
2 answers

Keeping type generic without η-expansion

What I'm doing: I'm writing a small interpreter system that can parse a file, turn it into a sequence of operations, and then feed thousands of data sets into that sequence to extract some final value from each. A compiled interpreter consists of a…
Victor Nicollet
  • 24,361
  • 4
  • 58
  • 89
3
votes
1 answer

ocaml type over-binding due to specialized recursive use of type

I have a parameterized type that recursively uses itself but with a type parameter specialized and when I implement a generic operator, the type of that operator is bound too tightly because of the case that handles the specialized sub-tree. The…
Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
2
votes
1 answer

Reasoning about types in Haskell

Chapter 16 of "Haskell Programming from First Principles" on page 995 has an exercise to manually work out how (fmap . fmap) typechecks. It suggests substituting the type of each fmap for the function types in the type of the composition…
2
votes
1 answer

Can Hindley-Milner return more than one error?

I am pretty new to type inference and was wondering if there are any good extensions or papers out there for HM that allows allowing more than one error. I might be missing something but if there is a unification error, can the type-checker proceed…
2
votes
0 answers

In regards to the Hindley-Milner Algorithm, what does a type constructor mean?

Say I have the letters A, B representing type variables which are initially unbound and a,b,c representing type constructors. I need then to show the bindings of type variables obtained through unification (or explain why if it fails). I'm given the…
jubibanna
  • 1,095
  • 9
  • 21
2
votes
3 answers

Hindley-Milner type of a function that takes itself as an argument

Suppose you had a function f that would be used as follows: (f f (x-1)) What can you deduce about the type of f? It seems to be recursive, ie, f :: (ftype) -> int -> int.
YOLT
  • 133
  • 2
  • 6
2
votes
2 answers

What is the difference between '.' and '<<<' when performing function composition?

I'm trying to perform function composition in Haskell, and I'm not sure which operator is the correct one to use. The docs contain these two type signatures: (.) :: (b -> c) -> (a -> b) -> a -> c (<<<) :: Category cat => cat b c -> cat a b -> cat…
achalk
  • 3,229
  • 3
  • 17
  • 37
2
votes
3 answers

Does Scala have a value restriction like ML, if not then why?

Here’s my thoughts on the question. Can anyone confirm, deny, or elaborate? I wrote: Scala doesn’t unify covariant List[A] with a GLB ⊤ assigned to List[Int], bcz afaics in subtyping “biunification” the direction of assignment matters. Thus None…
Shelby Moore III
  • 6,063
  • 1
  • 33
  • 36
2
votes
1 answer

Problems With Type Inference on (^)

So, I'm trying to write my own replacement for Prelude, and I have (^) implemented as such: {-# LANGUAGE RebindableSyntax #-} class Semigroup s where infixl 7 * (*) :: s -> s -> s class (Semigroup m) => Monoid m where one :: m class…
2
votes
1 answer

How to abstract over monads without fighting the type system in Haskell?

I'm currently building a server in haskell and as a newbie to the language, I'd like to try a new approach zu Monad composition. The idea is that we can write library methods like isGetRequest :: (SupportsRequests m r) => m Bool isGetRequest…
2
votes
1 answer

Haskell: Labeling an AST with type information using Algorithm W

We have an AST definition: data Term a = Lam String a | App a a | Var String deriving(Read,Show,Eq,Functor,Foldable,Traversable) And an F-Algebra for the type inference: type Wrapped m a = Enviroment -> m a type Result m = Wrapped…
2
votes
1 answer

Haskell: Rigid type variable error when passing function as argument

GHC is saying my function is too general to be passed as an argument. Here is a simplified version that reproduces the error: data Action m a = SomeAction (m a) runAction :: Action m a -> m a runAction (SomeAction ma) = ma -- Errors in…
Marcelo Lazaroni
  • 9,819
  • 3
  • 35
  • 41