tadeuzagallo / verve-lang

A functional language for the working hacker
https://verve-lang.org
MIT License
346 stars 7 forks source link

Variadic types trick compiler / runtime. #33

Open sparecycles opened 8 years ago

sparecycles commented 8 years ago

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:

tadeuzagallo commented 8 years ago

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:

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

sparecycles commented 8 years ago

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

tadeuzagallo commented 8 years ago

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