I have created a function in Haskell to counts the number of functions and operators in the given expression.
size :: Expr -> Int
size (Num n) = 1
size x = 1
size (Function f e) = 1 + size e
size (Operation o e1 e2) = 1 + size e1 + size e2
Though it's working as expected without any errors, I am getting a warning: [-Woverlapping-patterns] saying Pattern match is redundant. Any suggestions will be appreciated!
x
will never "fire", sincex
will capture any value. - Willem Van Onseme
such thatsize e
returns anything except 1. - chepner