Sorry for this title that I picked for a lack of better words.
Here is an typical example of function definition patterns I'm interested in:
h1 :: (Integer, Integer) -> Integer
h1 (x, 0) = f1 x
h1 (x, n) = g1 (x, n)
h2 :: (Integer, Integer) -> Integer
h2 (x, 0) = f2 x
h2 (x, n) = g2 (x, n)
h3 :: (Integer, Integer) -> Integer
h3 (x, 0) = f3 x
h3 (x, n) = g3 (x, n)
f1 :: Integer -> Integer
f1 x = x
g1 :: (Integer, Integer) -> Integer
g1 (x, n) = x
f2 :: Integer -> Integer
f2 x = 0
g2 :: (Integer, Integer) -> Integer
g2 (x, n) = 0
f3 :: Integer -> Integer
f3 x = 2*x
g3 :: (Integer, Integer) -> Integer
g3 (x, n) = x*n
As you can see, lines 1 through 11 are repetitive and exhibit a function definition scheme (and typing) that is common to h1, h2 and h3. This scheme is completed by the definitions that follow. This second part contains the actual "definition content" if I may say.
Is there a way to define a class of function definitions to avoid the repetitions of the first 11 lines?
I hope my question makes sense.
Thank you.
Aucun commentaire:
Enregistrer un commentaire