Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poly: infer - a new approach #37

Merged
merged 3 commits into from Jan 20, 2015
Merged

poly: infer - a new approach #37

merged 3 commits into from Jan 20, 2015

Conversation

chsievers
Copy link
Contributor

Maybe you like this version better.
You'll surely need the first commit.

@sdiehl
Copy link
Owner

sdiehl commented Jan 20, 2015

This is very good, the other approach worked but special cased the operators If/Op/Fix which wasn't as simple for the exposition. This uses the same approach for all syntax terms, which is great.

So this builds up the composition substitution tf by folding the intermediate substitution over each term in a list of subexpressions. I'll just have to figure out how to change the text of the tutorial to describe it.

inferPrim :: TypeEnv -> [Expr] -> Type -> Infer (Subst, Type)
inferPrim env l t = do
  tv <- fresh
  (s1, tf) <- foldM inferStep (nullSubst, id) l
  s2 <- unify (tf tv) t
  return (s2 `compose` s1, apply s2 tv)

  where inferStep (s, tf) exp = do 
          (s', t) <- infer (apply s env) exp
          return (s' `compose` s, tf . (TArr t))

sdiehl added a commit that referenced this pull request Jan 20, 2015
poly: infer - a new approach
@sdiehl sdiehl merged commit 846a6c1 into sdiehl:master Jan 20, 2015
@sdiehl sdiehl mentioned this pull request Jan 20, 2015
@chsievers chsievers deleted the inferL branch January 20, 2015 20:20
@sdiehl sdiehl mentioned this pull request Jan 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants