Question

For modelling software implemented with the imperative or procedural programming paradigm we have Flowcharts, process diagrams, etc.

For object oriented we have UML class diagrams, object diagrams, state diagrams, etc.

Is there an UML diagram suitable designing software implemented with functional programming?

Était-ce utile?

La solution

In short

Yes and no !

Yes you can model it !

The UML activity diagram models control flow and object flow. Both are very practical to model individual functions, function composition and function pipelines:

  • Functions would be represented by actions.
  • Composition can be shown with activitiy edges, if needed using pins to show that object flows from the one to the other (if you fear confusion between composition and sequencing).
  • Pattern matching in function definition can be represented with decision nodes in which you would use the patterns as guards for the outgoing branches.
  • Multiple input parameters could be represented with a join node, which has the advantage of underlining that the evaluation of the different parameters is not necessarily sequenced.

No, standard UML has no higher order functions

In standard UML, there is no simple way to my knowledge, to represent higher order functions:

  • Higher order functions are a core feature for functional programming.
  • But in UML an action cannot produce and action that is executed by another flow. It can not either accept actions as input to another action.
  • THis inner limitation comes from its roots, the petri nets, in wich control flow was represented by tokens that navigate accross a fixed network of nodes.

Perhaps some UML guru out there could find a workaround using invocation action, invoking the functor corresponding to an object of type function. But even if it would be possible, I don't think it would be easy to understand.

Note: that the same limitation occurs for non UML models: dataflows (DFD) and also functional decomposition models (SADT) always consider activities as fixed. After all, how could you make the difference between an arrow that connects two functions, and and arrow that delivers a new function?

Conclusion

  • to convince yourself of the feasibility, I invite you to look at some activity diagram examples, and -- despite these were designed with a procedural approach in mind -- try to imagine how you would implement them the functional way, you'd be surprised.

  • For the missing higher order activities, I don't know what to advice. Perhaps make a customized UML profile to allow to visually represent the actions produced as result of actions ?

Licencié sous: CC-BY-SA avec attribution
scroll top