
On Tue, 31 Mar 2015 22:11:47 +0200, Jeffrey Brown
It works! And I don't understand it! Particularly this line:
inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar
I'm considering the type signatures: map :: (a -> b) -> [a] -> [b] (<$>) :: Functor f => (a -> b) -> f a -> f b varGet :: Var a -> IO a map and <$> (fmap) are nearly synonymous; map seems like a special case of fmap. I gather the fmap must be to map inside the IO type that varGet returns, and the map must be mapping across some list. But what about their function arguments? Is map using the lambda expression, or is fmap? What function argument is the other one using? Are they both somehow sharing the lambda expression?
The expression f <$> x is equal to fmap f x . If f :: a -> b x :: IO a then fmap f :: IO a -> IO b . You could say, fmap lifts f to the IO monad (you could also use liftM for this). In your case, f is map (\e -> [hfill $ widget e]) and x is varGet myVar You stored a list of textEntrys in myVar, the lambda expression is mapped over this list. Another way to look at it: you can replace the line inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar with xs <- varGet myVar let inputs = map (\e -> [hfill $ widget e]) xs Regards, Henk-Jan van Tuyl -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --