Last active
December 10, 2015 18:48
-
-
Save elbrujohalcon/4476737 to your computer and use it in GitHub Desktop.
Dialyzer Magic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% @doc If you run dyalizer on this module it will complain saying | |
%% <pre>analyze_test.erl:11: The variable _ can never match since previous clauses completely covered the type []</pre> | |
%% It took me a while to figure out what it was doing... | |
%% It's not complaining that I call a function that returns [pid()] inside a function that should return [atom()]. | |
%% It says: "that function is fine... as long as it always return []" (which is both a list of pids and a list of atoms) | |
-module(analyze_test). | |
-export([exists/0]). | |
-spec list_of_atoms() -> [atom()]. | |
-spec list_of_pids() -> [pid()]. | |
list_of_pids() -> erlang:processes(). %% or other function that returns a (possibly empty) list of pids | |
list_of_atoms() -> list_of_pids(). | |
-spec exists() -> boolean(). | |
exists() -> case list_of_atoms() of [] -> false; _ -> true end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment