Куча говна / Говнокод #27377 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
%% This function is needed as a hack to guide dialyzer into inferring
%% the correct types.
-spec id(A) -> A.
id(A) ->
  A.

%% Где-то в header'е....

-define(deftarget(RECIPE), {RECIPE, fun my_module:id/1}).

%% A horrible, horrible hack to make Dialyzer infer right type of the promise return value
-define(want(TARGET),
        (fun() ->
             case TARGET of
               {_, ___IAmSorryYouHaveToSeeThisWorkaroundForDialyzer} ->
                 ___IAmSorryYouHaveToSeeThisWorkaroundForDialyzer(my_module:want(TARGET))
             end
         end)()).

Пути статический типизации в Erlang неисповедимы.

Запостил: CHayT CHayT, (Updated )

Комментарии (3) RSS

  • SEO: Запинываем Dialyzer, чтобы он проверил параметризованный тип.
    Ответить
  • P.S. Самый интересный кусок забыл:
    -type target(A) :: {recipe(), fun((A) -> A)}.
    Ответить
  • То ли дело C++!
    template<typename T, typename F>
    struct Promise {
        Promise(const F & func) : f(func) {}
    
        T resolve()
        {
            return f();
        }
    
        F f;
    };
    
    template<typename F>
    Promise(const F & func) -> Promise<decltype(func()), F>;
    
    int main()
    {
        auto promise = Promise([]() { return 16.1f; });
        auto result = promise.resolve();
        static_assert(std::is_same_v<decltype(result), float>);
    
        std::cout << "result == " << result << std::endl;
    }
    Ответить

Добавить комментарий

Где здесь C++, guest?!

    А не использовать ли нам bbcode?


    8