Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Haskell: Couldn't match expected type '[a0]' with actual type '([char], [int])'

My error message is as follows: ‘ Couldn’t match expected type ‘[a0]’ with actual type ‘([char], [Int])’ In the first argument of ‘zip’

I’m trying to do run length encoding, e.g

encode "aaaaabbbbcc"
[(’a’,5),(’b’,4),(’c’,2)]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My code is this:

encode [] = []
encode ls = zip((map head list), (map length list))
 where list = runs ls 

The ‘runs’ function returns [String], e.g
runs "aaaaabbbbcc"
["aaaaa","bbbb","cc"]

I don’t know how to fix it, any help or explanation would be appreciated!

>Solution :

You are trying to use C-style syntax to call zip, which is interpreted as zip getting a single tuple as its argument, rather than the two lists you intended.

encode ls = zip (map head list) (map length list)
   where list = runs ls
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading