I am reading with interest the online book โ I recognize you some erlang โ and try some exercises to test my understanding.
I made some changes using the example of fifo in the chapter Type specifications and Erlang , trying to define "typed_fifo (T)" (fifo, where all elements must be of the same type T)
My type specification:
-type typed_empty_fifo () :: {fifo, [], []}.
-type typed_nonempty_fifo (A) :: {fifo, nonempty_list (A), list (A)} | {fifo, [], notempty_list (A)}.
-type typed_fifo (A) :: typed_empty_fifo () | typed_nonempty_fifo (A).
and when I use it in the following spec function:
-spec empty (typed_empty_fifo ()) โ true;
(typed_nonempty_fifo(_)) -> false.
empty ({fifo, [], []}) โ true;
empty ({fifo, A, B}), is_list (A), is_list (B) โ false.
Dialyzer , - .
- , ?
, fifo, , , An Dialyzer , . , ( ) / .
, , bif/1, badarg!
23 > L = [1,2 | 3]. == > [1,2 | 3]
24 > is_list (L). == > true
25 > (L). == > :
in function length/1
called as length([1,2|3])