views:

471

answers:

6

More specifically, how do you model a functional program, or one developed using the Functional Style (without classes) using a diagram, and not textual representation, is it at all possible and could someone please direct me towards the nearest application that would do this (open source, of free as in beer, if you please)

+4  A: 

UML is a compendium of different types of modeling. If you are talking about the Object Diagram (Class Diagram), well you are not going to find anything that fits your desired use. But if you are talking about an Interaction Diagram (Activity Diagram) or Requirements Diagram (Use Case Diagram), of course they will help you and are part of the UML base.

jpabluz
A "requirements diagram" doesn't exist in UML (it's from SysML)
Michael Borgwardt
Nope, UML is Objects all the way. Everything is an Object, interaction diagrams model Objects, unless you treat a function as an object? I tried that a couple of years ago with a c# delegate which is a real object, it didn't work.
WeNeedAnswers
I kindly suggest some reading. http://www.springerlink.com/content/wwvwbt5wbm35cq1r/ should fit your interests.
jpabluz
@jpabluz Thanks will take a look at it, shame you have to pay for it :)
WeNeedAnswers
A: 

UML isn't only class diagrams, you know?

Most of the other diagram types (Use case diagrams, activity diagrams, sequence diagrams...) are perfectly applicable for a purely functional programming style. Even class diagrams could still be useful, if you simply don't use attributes and associations and interpret "class" as "collection of related functions".

Michael Borgwardt
I'm starting to see the original author's point, though. If you're just modeling a collection of related functions, you're not really 'modeling,' so much as organizing. I don't disagree that it's still _useful_, but it's not so much modeling behavior.
Marc Bollinger
@Marc: class diagrams aren't about modeling behaviour anyway; that's what activity and sequence diagrams are for.
Michael Borgwardt
UML is all about Classes, why else create such a paper based language?, I done a lot of other methods before and used methodologies that wrap up the Procedural Type Languages (SSADM to name one). Not yet seen one that does the same for functional languages. UML is all about messages and collaborations with descrete units of work called classes. But since a Function can be a Class, how would one model something without state? UML I feel is one hammer too many for something which is a pin.
WeNeedAnswers
@WeNeedAnsers: UML is not "paper based", nor is it "all about classes". Many of the concepts of UML have nothing to do with classes. Modeling something without state is as simple as refraining from using the model elements that constitute state.It looks to me like in this question you were looking mainly for validation of your misinformed prejudices.
Michael Borgwardt
@Michael. Not prejudices at all, I have worked with UML for a while now, before that I think it was called OMT or something. The "paper based language" is a language of expressing a system using visual and textual tools. Yes I agree that it does encompass more than just modelling and that most of it is about elicitation. But there have been many many methods and methodologies over the years, the selling point of UML was all about modelling of a system using Classes.
WeNeedAnswers
@Michael: An object without state does not have a behavioural pattern and is very difficult to model using Object notation. Please show me an example in UML, and I mean the heart and soul diagrams where a function can be modelled without an artificially created Object wrapping it up. Question is, how do you model a Function in UML without these "shoe horn fitting methods"? Prejudices I have not, I like UML. Just looking for a way to model functions :)
WeNeedAnswers
+6  A: 

Functional programmers generally don't have a lot of use for diagrams. Many functional programmers (but not all) find that writing down types is a good way to encapsulate the design relationships that OO programmers put into UML diagrams.

Because mutable state is rare in functional programs, there are no mutable "objects", so it is not usually useful or necessary to diagram relationships among them. And while one function might call another, this property is usually not important to the overall design of a system but only to the implementation of the function doing the calling.

If I were feeling a strong need to diagram a functional program I might use a concept map in which types or functions play the role of concepts.

Norman Ramsey
Thanks Norman, a bit of a recursive question, but I think that you have answered what I was feeling most eloquently.
WeNeedAnswers
revising this, I think that immutable types can be modelled. You can then pass these immutable objects into functions that act upon them, producing a new output. This question I posted was for a project I was working on. In the end I used UML, but split the objects up into functions and immutable types. It worked a treat.
WeNeedAnswers
+1  A: 

UML is an object approach because at graphical level you can not define functional modeling. A trick is to directly add constraints and notes at model and not in the diagram levels. I mean that you can write a full functional documentation on each model element directly in the metamodel and only display an object view using the UML editor. This is maybe stupid but I found this demo in French language exactly on the same subject and using EclipseUML Omondo : OCL and UML 2.2 (demo in French language 3mn): http://www.download-omondo.com/regle_ocl.swf

This demo explains how to add constraints directly on methods at metamodel level. The interesting point of this demo is that using a single model for the entire project allows to be flexible enough to extend traditional UML and avoid SysML, BPMN, DSL additionals models because all information is built on the top of the UML 2.2 metamodel. I don't know if it will be a success but this initiative is very interesting because reduce modeling complexity and open new frontiers !!

Hey all answers welcomed with open arms, the only stupid questions are the ones not asked. :) Thank you. I looked at constraints, think they are great, but if your feeling purest say using a language such as Haskell, it gets very awkward to apply something that has no state. The constraints become guards, but guards are so much more than constraints.
WeNeedAnswers
A: 

I haven't actually tried modelling a large system in UML and then going for a functional implementation, but I don't see why it shouldn't work.

Assuming the implementation was going to be Haskell, I would start by defining the types and their relationships using a class diagram. Allocate functions to classes by their main argument, but bear in mind that this is just an artefact of UML. If it was easier to create a fictional singleton object just to hold all the functions, that would be fine too. If the application needs state then I would have no problem with modelling that in a state chart or sequence diagram. If I needed a custom monad for application-specific sequencing semantics then that might become a stereotype; the goal would be to describe what the application does in domain terms.

The main point is that UML could be used to model a program for functional implementation. You have to keep in mind a mapping to the implementation (and it wouldn't hurt to document it), and the fit is far from exact. But it could be done, and it might even add value.

Paul Johnson
A: 

Functional programmers have their own version of UML, it is called Category Theory.

(There is a certain truth to this, but it is meant to be read with a touch of humour).

dtw