gleam
gleam copied to clipboard
Improve type inference of recursive functions
Gleam should be able to infer the types of this code:
pub fn call_with_self(f) {
f(f)
}
Currently it cannot.
https://elixirforum.com/t/gleam-a-statically-typed-language-for-the-erlang-vm/20349/165
so we can implement the let rec first? https://github.com/zjhmale/DHM/blob/master/src/hm/algw.clj#L139-L145
then the recursive function definition will be
pub rec fn fibonacci(n) {
case n {
0 | 1 -> 1
_ -> fibonacci(n -1) + fibonacci(n - 2)
}
}
there should always be a rec keyword before fn keyword
That should already work, all top level functions are implicitly letrec
Thank you for sharing that existing language, very cool!
hmm, so which part of type inference for recursion should we improve? I can not find any clue in the elixir forum thread.
Gleam should be able to infer the types of this code:
pub fn call_with_self(f) {
f(f)
}
Currently it cannot. Sorry for the confusion, I have not been putting much detail into these issues.
no worries will keep an eye on this issue then :)