I have some software design experience, and I am learning Haskell now. In many real world software developments, one faces a situation like the one given, for instance, below:
Suppose, I have this code
f1 a b c d = e
where
e1 = f2 b c (f3 a)
e2 = f4 d
e = e1 + e2
f2 b c d = n + c + d
where
n = f5 b
f5 n = n*n
f3 a = a * 2
f4 a = a + 3
Now if I want to change f5 so that it takes yet another parameter, I will have to change all the chain of functions right upto f1. It can be done as shown below. Note the added parameter x.
f1 a b c d x = e -- f1 needs to be changed
where
e1 = f2 b c (f3 a) x
e2 = f4 d
e = e1 + e2
f2 b c d x = n + c + d -- f2 needs to be changed
where
n = f5 b x
f5 n x = n*n -- f5 changed (**bang**)
f3 a = a * 2
f4 a = a + 3
Is this a normal Haskell way of doing this type of thing or is there a better (more Haskell-ish) way? I know such a change in API will disturb the client code, but how the impact can be kept minimum and is there any Hasekll way for it?
On a more general level: How well does Haskell perform in such cases (especially taking into consideration its immutable state feature)? What has it to offer the developers in this regard? Or is it that Haskell has got no role, per se, to play in this and that this is just a difficult software engineering problem (no such thing as future proof) that we have to keep up with?
I apologize for asking more than one question in a single post, but I cannot help as these are related to each other. Also, I could not find similar question asked, sorry if I might have missed it.
Aucun commentaire:
Enregistrer un commentaire