Skip to content

Instantly share code, notes, and snippets.

@sigwinch28
Created March 30, 2015 18:59
Show Gist options
  • Save sigwinch28/dc272b80a151a93e42eb to your computer and use it in GitHub Desktop.
Save sigwinch28/dc272b80a151a93e42eb to your computer and use it in GitHub Desktop.
The weakness of success types.
-module(discrep).
-export([run/0]).
% example of where type annotations fail to perform as expected.
% running `dialyzer discrep.erl` will return something similar to:
%
% Checking whether the PLT /home/joe/.dialyzer_plt is up-to-date... yes
% Proceeding with analysis... done in 0m0.29s
% done (passed successfully)
%
% even though there's a type error evident by the type annotations.
run() -> some_op([]).
-spec add_one(integer()) -> integer().
add_one(Num) -> Num + 1.
-spec some_op([integer()]) -> [boolean()].
some_op(Nums) -> lists:map(fun add_one/1, Nums).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment