[Haskell-cafe] Library for Sparse Vectors?
Alexander Solla
alex.solla at gmail.com
Wed Jul 27 00:45:16 CEST 2011
On Tue, Jul 26, 2011 at 3:27 PM, dokondr <dokondr at gmail.com> wrote:
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110726/3bf3515c/attachment.htm>
More information about the Haskell-Cafe
mailing list