Implementing interfaces in Erlang

前端 未结 2 1395
后悔当初
后悔当初 2021-02-14 23:24

How does one implement an interface in erlang? What is the structure of the modules or how is it setup?

I have a layered architecture and want to implement the interface

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-14 23:50

    An interface in the sense of a Java interface or an ML module signature does not exist in the dynamically typed Erlang world. You will have to document the behavior in a comment or provide a -spec contract for the dialyzer to look at.

    In general, the best way to approach a language is by not presuming you can map your existing knowledge too much into it, unless you happen to know a language that is "close" in concepts. Languages close to Erlang are Prolog and Scheme. Farther out comes Python and Ruby, but their reliance on an OOP design puts them into the horizon. Anything statically typed, Ocaml, Haskell, Java, C#, C++ and so on are definitely beyond the horizon.

提交回复
热议问题