How is code commonly organized in FP applications? Along what lines do you separate files, modules, directories, etc.?
How is code commonly organized in FP applications? Along what lines do you separate
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.