
On Tue, Jul 26, 2011 at 3:27 PM, dokondr
Thanks for the detailed reply and example! Using IntMap as a vector seems to be a good idea. In your example: 1) I would use:
dot = dot' * dot' dot' = sum . elems . intersectionWith (*) norm = sum . fmap (**2) . elems
instead of:
dot = sum . elems . intersectionWith (*) norm = (**0.5) . sum . fmap (**2) . elems
Your dot' is a function, so (dot' * dot') wouldn't type check.
2) I don't understand the syntax:
cosineSimilarity <$> lookup x space <*> lookup y space
What are <$> and <*>?
(lookup x space) has type (Maybe something). So does (lookup y space). We are using "applicative functors" to pull out values from (lookup x space) and (lookup y space), apply cosineSimilarity to the values we pulled out, and wrapping it all back up in a Maybe, depending on whether the lookups found something or not. <$> is exactly the same thing as fmap. <*> is harder to explain. But it is just plumbing. http://learnyouahaskell.com/functors-applicative-functors-and-monoids