Skip to content

Instantly share code, notes, and snippets.

@ChristophP
Last active April 16, 2019 19:36
Show Gist options
  • Save ChristophP/35d09ae04b2399ca398bcf1c7e97b167 to your computer and use it in GitHub Desktop.
Save ChristophP/35d09ae04b2399ca398bcf1c7e97b167 to your computer and use it in GitHub Desktop.
count occurance of words in a sentence
module OccuranceCount where
import Data.Foldable (foldl')
countWord :: String -> String -> Int
countWord needle =
foldl' (\acc word -> if word == needle then acc + 1 else acc) 0 . words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment