How to debug "Couldn't match expected type ... against inferred type" in Haskell? -


this error message getting:

couldn't match expected type `[(char, int)]'        against inferred type `(a, b)' in pattern: (c, n) in definition of `decode':     decode (c, n) = map (\ (c, n) -> replicate n c) 

and code

decode :: [(char,int)] -> string decode (c, n) = map (\ (c, n) -> replicate n c) 

the pattern (c,n) has type (a,b) not match type [(char, int)]. in other words you're saying argument list of pairs, pattern matches single pair.

also return value of map list of strings, not single string type signature suggests. if want single string, need use concatmap.

so code this:

decode pairs = concatmap (\ (c, n) -> replicate n c) pairs 

or just

decode = concatmap (\ (c, n) -> replicate n c) 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -