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

type inference for recursive functions #104

Merged
merged 1 commit into from
Dec 1, 2015

Conversation

edwadli
Copy link
Owner

@edwadli edwadli commented Dec 1, 2015

No description provided.

@@ -2,6 +2,8 @@
open Core.Std
open Sast

exception CantInferType of string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cant_infer_type

@kevin1
Copy link
Collaborator

kevin1 commented Dec 1, 2015

Read all the code and logic looks good. Give me a bit more time to digest and play around with the branch.

try Some(sast_expr_env expr)
(* Note that CantInferType is raised when an nh function has already
been seen higher up in the ast and it's not in tfuns_ref either *)
with CantInferType(_) -> None
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note if force was set to true (from the FunApply case), this case should not trigger. I could add that to the comments.

@kevin1
Copy link
Collaborator

kevin1 commented Dec 1, 2015

This would be a good negative test case, if we had them (#102):

type t1 = {
  tag = 1
  payload = 0
}

type t2 = {
  tag = 2
  payload = "0"
}

fun Typebender x = (
  if x$tag == 1 then
    Typebender (init t2)
  else
    x$payload
)

PrintEndline (Typebender (init t1))

For reference, the error message given is:

info: Function template type check failed. Inner exception: Both expressions in a conditional must have the same type (string and int found)
error: Incorrect types passed into function Typebender

| None -> let fake_sexpr = (Sast.LitUnit, case_true_t) in
Sast.Conditional((condition, condition_t), fake_sexpr, fake_sexpr), case_true_t
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of copy-pasted code here. It's not too bad so I filed tech debt #106 to fix it.

@kevin1
Copy link
Collaborator

kevin1 commented Dec 1, 2015

squash 'n 📧 📤 🏃 📮 🚚

got rid of unnecessary field in custom exception

made some things more ocamllic
@edwadli edwadli force-pushed the ed_recursive_type_inference branch from 3d5f026 to 11feaab Compare December 1, 2015 22:01
edwadli added a commit that referenced this pull request Dec 1, 2015
type inference for recursive functions
@edwadli edwadli merged commit 704e505 into master Dec 1, 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.

2 participants