[Haskell-beginners] More type errors I'm having trouble with

Daniel Trstenjak daniel.trstenjak at gmail.com
Fri Dec 4 08:35:18 UTC 2015


Hi Dan,

> io_hash_tuples <- map do_prefix_hash filenames

You're operating inside of the IO monad, so anything on the right hand
side of the `<-` has to have the type `IO`.

If you're looking up the type of `map`, you will see
that it doesn't return the right type.

Most likely you just wanted to create a binding like:

   let io_hash_tuples = map do_prefix_hash filenames


> hash_tuples <- sequence io_hash_tuples

`io_hash_tuples` is of type `[(IO String, String)]`, but
`sequence` expects a `[IO a]`.


Looking at your code, it's easier not to put the `IO String` computation
of the hash into a tuple, but first compute all hashes:

   hashes <- sequence (map Md5s.prefix_md5 filenames)


And if you want the hash and the filename grouped in a tuple:

   zip filenames hashes


Greetings,
Daniel


More information about the Beginners mailing list