# lingo

Fooling around with Traversable.

# nlp-scores/NLP/Scores.hs

`     , countJoint`
`     , countFst`
`     , countSnd`
`-    -- * Extracting lists of values from Counts`
`+    -- * Extracting lists of values from 'Counts'`
`     , fstElems`
`     , sndElems`
`     )`
` where`
` import qualified Data.Foldable as F`
`+import qualified Data.Traversable as T`
` import Data.Monoid`
` import Data.List hiding (sum)`
` import qualified Data.Set as Set`
` -- | Accuracy: the proportion of elements in the first sequence equal`
` -- to elements at corresponding positions in second`
` -- sequence. Sequences should be of equal lengths.`
`-accuracy :: (Eq a, Fractional c, F.Foldable t) =>  t a -> t a -> c`
`-accuracy xs = mean . map fromEnum . zipWith (==) (F.toList xs) . F.toList`
`+accuracy :: (Eq a, Fractional c, T.Traversable t) =>  t a -> t a -> c`
`+accuracy xs = mean . fmap fromEnum . zipWithTF (==) xs . F.toList`
` {-# SPECIALIZE accuracy :: [Double] -> [Double] -> Double #-}`
` `
` -- | Reciprocal rank: the reciprocal of the rank at which the first arguments`
` -- | List of values of second element`
` sndElems :: Counts a k -> [k]`
` sndElems = Map.keys . marginalSnd`
`+`
`+-- | @zipWithTF h t f@ zips the values from the traversable @t@ with`
`+-- the values from the foldable @f@ using the function @h@.`
`+zipWithTF :: (T.Traversable t, F.Foldable f) =>`
`+             (a -> b -> c) -> t a -> f b -> t c`
`+zipWithTF h t f = snd . T.mapAccumL map_one (F.toList f) \$ t`
`+  where map_one (x:xs) y = (xs, h y x)`
`+        `
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.