[Haskell-cafe] Library for Sparse Vectors?

Henning Thielemann lemming at henning-thielemann.de
Wed Jul 27 00:39:47 CEST 2011


On Wed, 27 Jul 2011, dokondr wrote:

> 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
> 2)  I don't understand the syntax:
> cosineSimilarity <$> lookup x space                  <*> lookup y space     
> 
> What are <$> and <*>?

They are from Control.Applicative and are applied to a Maybe type here. It 
means that cosineSimilarity is applied to the result of looking up 'x' and 
'y' in space. If 'x' or 'y' is not in space, then
   cosineSimilarity <$> lookup x space <*> lookup y space
  is Nothing.



More information about the Haskell-Cafe mailing list