
Dear List, I am stuck. I have a function that needs to apply each item of one list to every element of the second list in turn. So far, I have this function: checkNum :: Int -> [Int] -> (Int,[Int]) checkNum a b = (a,filter (check a) $ b) which implements what I need, but I now need to apply it to every element of the first list. I am looking for something like: list1 = [1,2,3,4,5,6] list2 = [1,2,3,4,5,6] map checkNum list1 list2 to return: [(1,[1]),(2[3,4,5]),(6,[3]) (I have tried to simplify this a little, so my apologies if it looks pointless - the real function is useful) Any help would be appreciated. Matt

On Fri, Apr 22, 2016 at 10:20:19PM +0100, Matt Williams wrote:
I am looking for something like:
list1 = [1,2,3,4,5,6] list2 = [1,2,3,4,5,6]
map checkNum list1 list2
to return:
[(1,[1]),(2[3,4,5]),(6,[3])
(I have tried to simplify this a little, so my apologies if it looks pointless - the real function is useful)
Any help would be appreciated.
Matt
Hey Matt, if what you want is [checkNum 1 list2, checkNum 2 list2, etc.] then map (flip checknum list2) list1 is what you want (flip signature being :: (a -> b -> c) -> b -> a -> c)

Thanks a lot for this.
Just to clarify (and ignoring the flip, which I can solve by rewriting the
checkNum function) - is this an example of currying?
M
On Fri, 22 Apr 2016 22:30 Francesco Ariis,
On Fri, Apr 22, 2016 at 10:20:19PM +0100, Matt Williams wrote:
I am looking for something like:
list1 = [1,2,3,4,5,6] list2 = [1,2,3,4,5,6]
map checkNum list1 list2
to return:
[(1,[1]),(2[3,4,5]),(6,[3])
(I have tried to simplify this a little, so my apologies if it looks pointless - the real function is useful)
Any help would be appreciated.
Matt
Hey Matt, if what you want is
[checkNum 1 list2, checkNum 2 list2, etc.]
then
map (flip checknum list2) list1
is what you want (flip signature being :: (a -> b -> c) -> b -> a -> c) _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

On Sat, Apr 23, 2016 at 08:50:32AM +0000, Matt Williams wrote:
Thanks a lot for this.
Just to clarify (and ignoring the flip, which I can solve by rewriting the checkNum function) - is this an example of currying?
Example of partial application! Currying is when you have a function like: f :: (a, b) -> c and transform it to: g :: a -> b -> c Open ghci and play a bit with `curry` and `uncurry` to get the idea!
participants (2)
-
Francesco Ariis
-
Matt Williams