[Haskell-beginners] using the joker "_" on a constructor

TP paratribulations at free.fr
Thu Sep 19 12:44:58 CEST 2013


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




More information about the Beginners mailing list