hindley-milner

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

半世苍凉 提交于 2020-01-14 03:35:16
问题 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 must have type Option[⊥] (i.e. Option[Nothing] ), ditto Nil type List[Nothing] which can’t accept assignment from an Option[Int] or List[Int] respectively. So the value restriction problem originates from directionless unification and global

runST with Hindley-Milner type system

霸气de小男生 提交于 2020-01-01 04:42:05
问题 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 question is the following: is it possible to extend the HM type system with an ad-hoc rule for typing runST applications so that the ST monad is safely escapable, without introducing rank-2 types? More precisely, runST would have type forall s a. ST s

Haskell: Labeling an AST with type information using Algorithm W

自古美人都是妖i 提交于 2019-12-07 18:41:22
问题 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 (Type,Substitution) w :: (MonadState Int, MonadError TypeError) => Term (Result m) -> Result m w term env = ... We can get the result of running the inference using cata : infer :: (MonadState Int, MonadError TypeError) => Fix Term -> Result m infer ast = cata hm

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

强颜欢笑 提交于 2019-12-06 21:35:33
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 must have type Option[⊥] (i.e. Option[Nothing] ), ditto Nil type List[Nothing] which can’t accept assignment from an Option[Int] or List[Int] respectively. So the value restriction problem originates from directionless unification and global biunification was thought to be undecidable until the recent research linked above. You may wish to view the

Haskell: Labeling an AST with type information using Algorithm W

馋奶兔 提交于 2019-12-06 06:21:37
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 (Type,Substitution) w :: (MonadState Int, MonadError TypeError) => Term (Result m) -> Result m w term env = ... We can get the result of running the inference using cata : infer :: (MonadState Int, MonadError TypeError) => Fix Term -> Result m infer ast = cata hm ast But now I want the result to be the original AST annotated with type information for each expression,

Hindley Milner Type Inference in F#

这一生的挚爱 提交于 2019-12-04 21:57:07
问题 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 works. 回答1: Fun stuff! First we invent a generic type for sumList: x -> y And get the simple equations: t(lst) = x ; t(match ...) = y Now you add the equation: t(lst) = [a] because of (match lst with [] ...) Then the equation: b = t(0) = Int ; y = b Since 0 is

What are the limits of type inference?

喜夏-厌秋 提交于 2019-12-03 05:48:52
问题 What are the limits of type inference? Which type systems have no general inference algorithm? 回答1: Joe Wells showed that type inference is undecidable for System F, which is the most basic polymorphic lambda calculus, independently discovered by Girard and Reynolds. This is the most important result showing the limits of type inference. Here's an important problem that is still open: what is the best way to integrate Generalized Algebraic Data Types into Hindley-Milner type inference? Every