Chapter 6. Internal DSL design in Scala


This chapter covers

  • Scala as a language
  • Developing an internal DSL in Scala
  • Composing multiple DSLs
  • Using monadic structures

In the earlier chapters, we’ve been through the pros and cons of DSL-driven development. By now you must have realized that for the parts of your application that need to model business rules, a DSL can go a long way toward improving the communication path between the development team and the team of domain experts. In the last chapter, we discussed how you can use a few of the dynamic languages on the JVM as hosts for designing internal DSLs. In this chapter, we’ll look at the most promising candidate from among the statically typed ones, Scala.

Like all implementation discussions, this is going to be a programming-intensive chapter in which we’ll start with the suitability of Scala as a host for implementing internal DSLs, and then dive right into real-world DSL design. Figure 6.1 is a roadmap of our journey through this chapter.

Figure 6.1. Our roadmap through this chapter

6.1. Why Scala?

6.2. Your first step toward a Scala DSL

6.3. Let’s DSL in Scala!

6.4. Building a DSL that creates trades

6.5. Modeling business rules with a DSL

6.6. Stitching ’em all together

6.7. Composing DSLs

6.8. Monadic structures in DSL

6.9. Summary

6.10. References