开发者

How to structure an application written in a functional language?

How is code commonly organized in FP applications? Along what lines do 开发者_如何学JAVAyou separate files, modules, directories, etc.?


How to structure an application written in a functional language?

No differently than in any other kind of application:

  • Every module hides a secret.

  • A design decision that is likely to change should be encapsulated in a module.

  • A module might export a single main type, a couple of auxiliary types, and a whole bunch of related operations.

  • Module cohesion and coupling are still as important as Yourdon and Constantine said they were back in the 1970s—although in a functional language you seldom have to worry about "sequential" forms of cohesion and coupling.

  • Many functional languages require one module per file, but the ML dialects offer a great deal more flexibility. However the overwhelming practice is to put a module and its interface into separate files. Objective Caml enshrines this convention into their compiler.

In short, it's still true that representation is the essence of programming (Fred Brooks), and as in any other large application, your modules should be organized to avoid exposing representation gratuitously.

The one thing that's a little different in a functional language is that you might provide a module that encapsulates some pattern of execution as embodied in a higher-order function. For example, I wrote a module based on Bubble Search; my code takes any greedy algorithm and automatically converts it into a bubble-searchy algorithm. But a module like this, which is entirely about code and has no real data structure, is quite rare.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜