We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
When you do list comprehensions in Haskell and draw from multiple lists (by doing x <- list), then the result is a list doing the thing in front for all posible combinations from the lists. Here's an example:
[(a,b)|a<-[1,2,3],b<-[4,5]]
gives you
[(1,4),(1,5),(2,4),(2,5),(3,4),(3,5)]
In _s_batra's example, the a is kinda unused (which also means that by convention it should be named _), but it simply repeats the num for each element in [1..n] (aka n times).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
List Replication
You are viewing a single comment's thread. Return to all comments →
When you do list comprehensions in Haskell and draw from multiple lists (by doing
x <- list
), then the result is a list doing the thing in front for all posible combinations from the lists. Here's an example:gives you
In _s_batra's example, the
a
is kinda unused (which also means that by convention it should be named_
), but it simply repeats thenum
for each element in[1..n]
(akan
times).