Haskell pattern matching match Map.empty any with any Map.Map k v -


i writing function has different operations depending on map.map in argument if map empty or not

here code:

import qualified data.map.lazy map  testf :: (ord a, num a) => map.map a -> [a] -> [a] testf empty _  = [1024] testf _ []     = [] testf m (x:xs) = [x] ++ (testf m xs)  main =   let = map.fromlist [(1,2), (3,4)]   print $ testf map.empty [1,2,3] -- show [1024]   print $ testf [1,2,3] -- show [1024]   print $ == map.empty -- false 

of course ghc give me notification lastest line of function redundant.

pattern match redundant    in equation ‘testf’: testf m (x : xs) = 
  1. why every map.map can match map.empty?
  2. what should implement requirement?

thank you.

you're not matching against map.empty, you're matching against empty, local variable bound whatever map coming in. can't match against map.empty because it's not constructor.

what can instead is:

testf m _ | map.null m = [1024] 

i.e. use guard check whether m empty.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -