Look at it from the inside, out. What does const do?
Const is a function that takes two parameters and always returns the first one. For instance, const True x is True, for all x. What's \x -> map (const x) then? (or map.const in my case) It's a function that takes something and maps all the elements in a list onto that something. i.e. you say 1 [2, 3, 4]; it replies [1, 1, 1]. What's cycle [True, False]? It's simply the list [True, False, True, False, ...]. What's (map (\x -> map (const x)) (cycle [True, False]))? It's a list of functions that map their lists to lists of True or lists of False (alternatively). And what does the zipWith ($) do? It applies the functions we've just built onto the lists you give it. Cheers, Alex On Saturday 03 April 2010 16:34:21 Maur Toter wrote: > Thanks again! > > The last part I cant understand: > So I give it for example > zipWith ($) (map (\x -> map (const x)) (cycle [True, False])) [[1,2],[3]] > > Okay, because of ($) it takes the first element of the last part which is > [1,2] and apply the function on it > But how makes this: map (\x -> map (const x)) (cycle [True, False]) > [True,True] from [1,2]? > Then he takes [3] but how makes [False] from that? > > It easily can be that my functional programming knowledge isn't enough to > understand this and maybe I misunderstood it already. But I hope I'll be > able to do so.. > > Thanks: > Maur Toter > > so > > On Sat, Apr 3, 2010 at 4:31 PM, Edward Z. Yang <[email protected]> wrote: > > Excerpts from Maur Toter's message of Sat Apr 03 10:29:34 -0400 2010: > > > What does the ($) at zipWith? > > > > ($) is function application > > > > Prelude> :t ($) > > ($) :: (a -> b) -> a -> b > > > > Cheers, > > Edward _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
