views:

556

answers:

6

UML is a standard aimed at the modeling of software which will be written in OO languages, and goes hand in hand with Java. Still, could it possibly be used to model software meant to be written in the functional programming paradigm? Which diagrams would be rendered useful given the embedded visual elements?

Is there a modeling language aimed at functional programming, more specifically Haskell? What tools for putting together diagrams would you recommend?

editted 09/02: What I'm looking for is the most visual, lightest representation of what goes on in the code. Easy to follow diagrams, visual models not necessarily aimed at other programmers. I'll be developing a game in Haskell very soon but because this project is for my graduation conclusion work I need to introduce some sort of formalization of the proposed solution. I was wondering if there is an equivalent to the UML+Java standard, but for Haskell. Should I just stick to storyboards, written descriptions, non-formalized diagrams (some shallow flow-chart-like images), non-formalized use case descriptions?

+24  A: 

I believe the modeling language for Haskell is called "math". It's often taught in schools.

John Millikin
For example, would game theory be useful in modelling the game you said you were developing? I don't know, I'm a grad student in computational linguistics, and my statistical and linguistic models do a pretty good job at capturing the high-level view of my Haskell (and C++!) code.
Nathan Sanders
@Nathan Sanders: Game theory doesn't really have much to do with computer games. It has to do with many other things in the world.
yairchu
I bet half of game developers don't even know what Game Theory is, much less use it.
Austin Kelley Way
+8  A: 

Yes, Haskell.

I get the impression that programmers using functional languages don't feel the need to simplify their language of choice away when thinking about their design, which is one (rather glib) way of viewing what UML does for you.

Ori Pessach
You seem to miss the point of formal modeling. In certain circles of software development, formal modeling is a requirement, no matter how bureaucratic you consider this to be. There are several levels of involvement from different teams on the conclusion of a project and many of the people involved have no idea about the code. They don't need to have, it'd be a major hassle if that was asked of them. The formal modeling is there to assure that they'll get a better view of how things work so that they can perform their roles in the development.
codnik
Oh, but don't think I totally disagree with you (although I believe your answer adds nothing). I particularly think it's a bore, but I need to have some sort of formal modeling in my graduation conclusion work (using Haskell to develop a game) or a very good excuse for the lack of it.
codnik
I agree that modeling disciplines try to do everything you describe. I just haven't seen any evidence that they achieve any of that in the last 20 years. I actually like the answer that lists "math" as a good modeling language for functional languages. You can't get more formal than that.
Ori Pessach
Oh, but don't think I totally disagree with YOU - I would just point out that finding something a bore is a good indication that that something isn't particularly useful. People have an innate ability to recognize useful things around them - just look at any toddler holding a stick for a universal example. There's nothing about UML that suggests it would be of any use to man or beast, and I think your reaction to it is a reflection of that.
Ori Pessach
In that case, just delete the implementations of all the functions, and leave only the signatures. To an intelligent functional programmer, that leaves the implementation reasonably apparent, but looks like a simplified 'model' to someone less knowledgeable. Bonus points for arranging these in some visualization. Also, http://portal.acm.org/citation.cfm?id=99370.99404 describes how to generate some code based just on the types in the 'model' :-).
Novelocrat
You got a good point there Ori. I just don't go acknowledging that all the time because people might get the impression that I'm a bureaucracy hater just for the sake of it. I'm not against all rules, but I like to be practical.Novelocrat, I understand what you mean, I've come across similar comments about this issue. What I'm looking for is the most visual, lightest representation of what goes on in the code. I guess I should just go with a colorful storyboard and forget about the cold diagrams?
codnik
codnik: Never underestimate the importance of external factors when assessing requirements. In your situation, choosing and using a modeling language is entirely appropriate. In day to day practice of the craft, my impression so far has been that it's often counterproductive and that the people who insist on it are less effective than people who are happy to do without it. My evidence is all anecdotal, of course.
Ori Pessach
+10  A: 

We use theorem provers to do formal modelling (with verification), such as Isabelle or Coq. Sometimes we use domain specific languages (e.g. Cryptol) to do the high level design, before deriving the "low level" Haskell implementation.

Often we just use Haskell as the modelling language, and derive the actual implementation via rewriting.

QuickCheck properties also play a part in the design document, along with type and module decompositions.

Don Stewart
+1  A: 

I have watched a few video interviews, and read some interviews, with the likes of erik meijer and simon peyton-jones. It seems as when it comes to modelling and understanding ones problem domain, they use type signatures, especially function signatures.

Sequence diagrams (UML) could be related to the composition of functions. A static class diagram (UML) could be related to type signatures.

fsl
+1  A: 

In Haskell, you model by types.

Just begin with writing your function-, class- and data signatures without any implementation and try to make the types fit. Next step is QuickCheck.

E.g. to model a sort:

class Ord a where
    compare :: a -> a -> Ordering

sort :: Ord a => [a] -> [a]
sort = undefined

then tests

prop_preservesLength l = (length l) == (length $ sort l)
...

and finally the implementation ...

Dario
A: 

What would be the point in modelling Haskell with Maths? I thought the whole point of Haskell was that it related so closely to Maths that Mathematicians could pick it up and run with it. Why would you translate a language into itself?

When working with another functional programming language (f#) I used diagrams on a white board describing the large blocks and then modelled the system in an OO way using UML, using classes. There was a slight miss match in the building blocks in f# (split the classes up into data structures and functions that acted upon them). But for the understanding from a business perspective it worked a treat. I would add mind that the problem was business/Web oriented and don't know how well the technique would work for something a bit more financial. I think I would probably capture the functions as objects without state and they should fit in nicely.

It all depends on the domain your working in.

WeNeedAnswers