úÎ(_%Œ#      !" Safe-Infered#$%&#$%&#$%&portable (GHC, Hugs)stable f@mazzo.li Safe-Infered A , is a list of declaration and an expression @ representing what the program does. Each declaration can use 5 previous declarations only (no mutual recursion). FA declaration (binds a certain expression to a variable). We add this G abstraction on top of let so that we can write programs more easily ) (leaving let for local declarations). 4Data type representing lambda-calculus expressions. 0Fixed point combinator (bye bye normalization). Polymorphic let. "An expression applied to another. A lambda abstraction.  A variable. An identifier (predictably a ').  ()*+    ()*+portable (GHC, Hugs)stable f@mazzo.li Safe-Infered4An assumption about the type of a (value) variable. ,What can go wrong when inferring the types. Generic error, needed for the , instances. -Unbound variable (value, not type variable). 7The user is trying to construct an infinite type, e.g. ' a = a -> b'. DUnification failed (e.g. when trying to unify a quantified variable  with an arrow type). A type scheme. The -/ represents the number of quantified variables  (must be >= 0). Invariants: all the  in the scheme must be < of the - . If this 2 is not the case the program crashes badly (see .). GA data type to represent types. Note that the functions of this module  should return  s without 's (we want the schemes to have no free  variables). FA quantified variable. We use a different constructor (separated from @ TyVar) so that there can be no clash between the two, and we " immediately know what is what. The arrow type (A -> B) A type variable. GA type variable. We use integers for easy generation of new variables.  Types an  given a list of . Returns either a  if  the algorithm failed or a  if it succeeded.  Types a list of declarations (a #) returning the principal type for : each declaration and the type of the final expression. /#Useful instance on lists of types.  !"012345/6 !" !" !"012345/6portable (GHC, Hugs)stable f@mazzo.li Safe-Infered#  !"7      !"#$%&'()*+,-./0123456789:;<=>ml-w-0.1Language.ML.SyntaxLanguage.ML.TypeCheck Applicative Language.MLProgramDeclExprFixLetAppLamVarId parseExpr parseExpr' parseProgram parseProgram' prettyExpr prettyDecl prettyProgramAssump:>: TypeErrorUnboundVariable InfiniteTypeUnificationFailSchemeTypeTyGenTyArrTyVartypeExpr typeProgram prettyType prettyScheme<$><*>*><*baseGHC.BaseString $fShowProgram $fShowExpr $fReadProgram $fReadExprtransformers-0.3.0.0Control.Monad.Trans.ErrorErrorghc-prim GHC.TypesIntfreshen $fTypes[] $fShowScheme $fShowType $fTypesAssump$fMonadInferErrorT$fErrorTypeError $fTypesScheme $fTypesType