
19 Sep
2013
19 Sep
'13
10:44 a.m.
Christian Maeder wrote:
In order to avoid your duplicate code consider to define "Foo" as follows:
data Foo = F FB Int data FB = Foo | Bar
f (F _ n) = even n
Thanks a lot. Your solution, also given by Kim-Ee Yeoh, is the one I prefer: • the common features are factorized in the type; • the values are deconstructed by pattern matching maybe in a clearer way; • `_` is explicitly used, making clear in a blink of an eye that we have some common behavior over several types. TP