simple type inference for structural polymorphism l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Simple Type Inference for Structural Polymorphism PowerPoint Presentation
Download Presentation
Simple Type Inference for Structural Polymorphism

Loading in 2 Seconds...

play fullscreen
1 / 12

Simple Type Inference for Structural Polymorphism - PowerPoint PPT Presentation


  • 163 Views
  • Uploaded on

Simple Type Inference for Structural Polymorphism. Jacques Garrigue Type Refinements Seminar. Motivation. HM (X) used to explain structural polymorphism Assume subtyping absent HM(X) is not a simple extension to previous algorithms Constraints occur in all types

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Simple Type Inference for Structural Polymorphism' - cleatus


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
simple type inference for structural polymorphism

Simple Type Inference for Structural Polymorphism

Jacques Garrigue

Type Refinements Seminar

motivation
Motivation
  • HM (X) used to explain structural polymorphism
  • Assume subtyping absent
  • HM(X) is not a simple extension to previous algorithms
    • Constraints occur in all types
    • Type errors become unreadable
proposed solution
Proposed Solution
  • Have “local constraints” : constraints on top of classic Hindley-Milner system
  • Constraints embedded in kinding context for type variables
  • Less powerful than HM(X)
type system
Type System
  • Types  ::= 

| u

| !

  • Kind envs K ::= 

| K, :: (C,9.R)

  • Polytypes  ::= 

| 8.K . 

free variables of types
Free Variables of Types
  • FVK(81,,n.K’ . ) =

FVK,K’()\{1,,n}

  • FVK,:(C,9 .R) () = {}[ FVK(R)
  • FVK(u) = 
  • FVK(1!2) = FVK(1)[ FVK(2)
type substitutions
Type Substitutions
  • K `:K’

( is admissible between K and K’)

If for all ::(C,9.R) 2 K, () is ’

    • ’::(C’,9’ R’) 2 K’
    • C’ ² C
    •  :  !’ s.t. ( R)µ R exists
typing rules
Typing Rules

K,K0` : K Dom ()½ B

K;,x:8 B.Ko. ` x:()

K;,x:` e:’

K;` fun x ! e : !’

K;` e1:!’ K;` e2:

K;` e1 e2 : ’

typing rules contd
Typing Rules (contd.)

K;` e1 :  K;, x:` e2 : 

K;` let x = e1 in e2 : 

K; ` e :  B = FVK() \ FVK ()

K|B; ` e : 8 B.K|B.

Gen

compare with hm x
Compare with HM (X)

K;` e :  B = (FV () [ FV(KB) ) FV ()

9 B.K;` e : 8 B.KB.

KBµ K containing all kinds related to B

Generalizes over tyvars not “relevant”

HMX-Gen

relevant type variable
Relevant type variable
  • Technical definition in paper
  • Basically, the meaning of the type depends on what kind the variable gets
  • Recall, kinds include constraints
  • Useful to understand constraints/ type errors
benefits
Benefits
  • Easier understanding of constraints
    • e.g. If  FVK(1) [ FVK(2),

solving K Æ1 = 2 does not give us more information about 

conclusions
Conclusions
  • Less powerful than HM (X) : no subtyping
  • Gives less precise answers
  • More practical (??)
  • Sufficient for most purposes