I prefer to write the name of the function when I map the templates to something that is shown in your case. I find this more readable.
I prefer to use guards when I have some conditions for function arguments, which helps to avoid the if else , which I would have to use if I had to follow the first pattern.
So, to answer your questions
Do you think that second example is more readable, modifiable and elegant?
No, I prefer the first one, which is simple and readable. But more or less it depends on your personal taste.
What about generated code?
I donβt think there will be any difference in the generated code. Both are just templates.
What are cons?
Well pattern sets are useful for patternmatch instead of using let or something cleaner.
addLookup env var1 var2 | Just val1 <- lookup env var1 , Just val2 <- lookup env var2 = val1 + val2
Well, of course, you need to use the extension, and also it is not Haskell98 (which you might not consider part of con)
On the other hand, for trivial pattern matching in function arguments, I simply use the first, simple and readable method.
source share