Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 18. Types and Documentation > Types in Erlang - Pg. 395

CHAPTER 18 Types and Documentation The basic types in Erlang--integers, floating-point numbers, atoms, strings, tuples, and lists--were introduced in Chapter 2; records were covered in Chapter 7; and further types--binaries and references--in Chapter 9. When we have declared functions and other definitions, we have also given an informal description of the types of their inputs and outputs. This chapter shows how you can write down the types of functions as a part of their formal documentation in Erlang, using the EDoc documentation framework, written by Richard Carlsson. What you write down as the type of a function can be checked for consistency against the function definition using the TypEr tool, built by the im- plementers of Dialyzer. TypEr will infer types without any user input, and so it can be an essential tool for program understanding. TypEr and Dialyzer are the result of the High Performance Erlang (HiPE) team's research at Uppsala University. All of these tools are part of the standard Erlang distribution. Types in Erlang Let's start this chapter with an example and follow it with an overview of the type notation for Erlang. An Example: Records with Typed Fields We discussed record definitions earlier in the book. In the example of the mobile user database in Chapter 10, you saw a declaration of a record to hold information about a particular user of the mobile phone system: -record(usr, {msisdn, id, status = enabled plan, services = []}). %int() %term() %atom(), enabled | disabled %atom(), prepay | postpay %[atom()], service flag list The usr record has five fields, and in the comments that follow, each field type is indicated. 395