My question is related to the more general question of developing a Haskell program. But I would like to dwell on a specific precedent.
I defined a data type (e.g. Foo ) and used it in a function (e.g. f ) using pattern matching. Later I realized that the type ( Foo ) requires some extra field to support the new functionality. However, adding a field will change the way this type is used; those. Existing type-specific functions may be affected. It is impossible to avoid adding new functionality to existing code, no matter how unattractive it is. I am wondering what the best practices at the Haskell language level are to minimize the impact of such modifications.
For example, existing code:
data Foo = Foo { vv :: [Int] } f :: Foo -> Int f (Foo v) = sum v
Function f will be a syntax error if I add another field to Foo :
data Foo = Foo { vv :: [Int] uu :: [Int] }
However, if I defined the function f as follows:
f :: Foo -> Int f foo = sum $ vv foo
then even with a modification to Foo , f will still be correct.
design haskell
Causality
source share