In my process of learning Elixir, I play with Dialyzer to overlay types on my functions. In this regard, I noticed that Dialyzer does not seem to check the types of anonymous functions.
In the example below, I pass an anonymous function that adds two numbers and returns a number (t::number -> number) in the all? . So I do not return boolean as promised in all? spec (t::any -> boolean) .
defmodule Exercises do @spec all?([t::any], (t::any -> boolean)) :: boolean def all?([], _), do: true def all?([h|t], con) do if con.(h) do all?(t,con) else false end end @spec funski() :: boolean def funski() do all?([1,1,2], &(&1 + 1)) end end
Dialyzer does not seem to report any errors or warnings for this code, and I am interested if Dialyzer cannot check for such errors or if I am doing something wrong.
source share