[Haskell-cafe] want to post haskell question

Miguel Mitrofanov miguelimo38 at yandex.ru
Tue Feb 2 05:01:14 EST 2010

> |multSM  d m = [[(b*a)| b<-[d], a<-(head m)]]

Well, let's see what do we have here.

We have []'s around something. "Something" is [(b*a)| b<-[d], a<-(head m)], which is just a legal Haskell value, so our "mutlSM d m" has to be a one-element list, with the only element being equal to 
what we put inside the brackets. It's like [1] or ["Hello"], just with more complex expression inside.

This unique value is, as we've seen, [(b*a)| b<-[d], a<-(head m)]. Here we also have []'s around something, but this new "something" is NOT a legal Haskell value; it's a list comprehension. That means 
that we have something like this:

multSM d m = [concatMap (\b -> concatMap (\a -> b*a) (head m)) [d]]

Now, concatMap f [d] = f d, so

multSM d m = [concatMap (\a -> d*a) (head m)]

and if m = [m1:ms], then

multSM d m = [concatMap (\a -> d*a) m1]

So, you take first row ("head" only takes the first element of the list, you know), multiply it by "d", and make a one-element list of it.

More information about the Haskell-Cafe mailing list