Typespec for an infinite recursive function

Hi! I have this kind of function:

@spec run(fun()) :: :ok
def run(task) do
  task.()
  run(task)
end

Dialyzer doesn’t complain about this. I can use almost anything as return type. For example, this works too:

@spec run(fun()) :: String

But this does not work:

@spec run(fun()) :: none()

Does the return type matter in this case? Why Dialyzer does not complain about it and why I cannot use none() as return type?

I haven’t had time to try this, but how about:

@spec run(fun()) :: no_return()
def run(task) do
  task.()
  run(task)
end
5 Likes

Hey thanks, it seems to work. :grinning:

1 Like

Perfect timing. I just sat down at my laptop and tried it, and it does work! :+1:

1 Like