Skip to content

Instantly share code, notes, and snippets.

@elbrujohalcon
Last active December 10, 2015 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbrujohalcon/4476737 to your computer and use it in GitHub Desktop.
Save elbrujohalcon/4476737 to your computer and use it in GitHub Desktop.
Dialyzer Magic
%% @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