What is the return type of a tail-recursive function

Loïc Hoguin essen@REDACTED
Thu Feb 13 08:21:39 CET 2020


None, it doesn't return.

You can use no_return() for these cases.

-spec loop() -> no_return().

You would do the same for functions that always throw an exception since 
they don't return either.

Cheers,

On 13/02/2020 07:21, by wrote:
> Hi,
> 
> What is the return type of a tail-recursive function?
> 
> I guess it is a fun(), am I right? (actually I doubt it, but have no 
> idea what the type is)
> 
> A strange loop :-)
> 
> Please see example as below:
> ====
> -module(test).
> 
> -export([start/0]).
> -export([loop/0]).
> 
> -specstart() ->pid().
> 
> start() ->
> spawn(fun() ->loop() end).
> 
> -specloop() ->fun().
> 
> loop() ->
> receive
> Any->
> Any,
> loop()
> end.
> ====
> 
> Kind Regards,
> Yao

-- 
Loïc Hoguin
https://ninenines.eu


More information about the erlang-questions mailing list