verve-lang icon indicating copy to clipboard operation
verve-lang copied to clipboard

Variadic types trick compiler / runtime.

Open sparecycles opened this issue 8 years ago • 3 comments

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.).

sparecycles avatar Jul 09 '16 15:07 sparecycles

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.

tadeuzagallo avatar Jul 09 '16 15:07 tadeuzagallo

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

sparecycles avatar Jul 09 '16 16:07 sparecycles

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

tadeuzagallo avatar Jul 13 '16 21:07 tadeuzagallo