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

Variadic types trick compiler / runtime. #33

Open
sparecycles opened this issue Jul 9, 2016 · 3 comments
Open

Variadic types trick compiler / runtime. #33

sparecycles opened this issue Jul 9, 2016 · 3 comments
Labels

Comments

@sparecycles
Copy link

Attempting to generalize the maybe type in the tests, I found two issues:

type maybe<type> {
  Just(type)
  None()
}

implementation printable<maybe<string>> {
  fn to_string(a) {
    match a {
      Just(x) => "x"
      None() => "None<string>"
    }
  }
}

fn print_maybe<type>(x: maybe<type>) -> void {
  print(x) // not all maybes are printable
}

print(Just("abc"))

// maybe<int> is not printable...
print_maybe(Just(42))
$ ./verve input.vrv 
1.53825e-154
1.53825e-154

I think the two issues are:

  • the output of print(Just("abc")) is some undefined value (the number changes slightly between runs) interpreted as a float.
  • print_maybe can be used with non-printable maybes, (when one kind of maybe is printable.).
@tadeuzagallo
Copy link
Owner

tadeuzagallo commented Jul 9, 2016

Other than the fact that the type checker is not that smart yet (😞), there are a couple hacks that I have to fix to make it more sane:

  • The signature of print says it takes a printable, but it never calls to_string in the value. It's an old version of the function that expects the pointer to be NaN-boxed and checks the type tag.
  • In the case that the print function doesn't recognise the type tag, it'll print anything as doubles: that was a quick hack to add double support without rewriting the whole print logic (I know, it's bad)

I'll try to fix these issues soon, and it should, at least, improve the error, instead of just printing garbage.

@sparecycles
Copy link
Author

And here I thought I had discovered a horrid runtime flaw, and all I did was hit some temporary hack.

@tadeuzagallo
Copy link
Owner

Accidentally closed it, just meant to mention it from the commit message... :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants