Skip to content

Instantly share code, notes, and snippets.

@heath
Created January 29, 2020 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heath/527aca0963f3484deb29a13c2a693ca1 to your computer and use it in GitHub Desktop.
Save heath/527aca0963f3484deb29a13c2a693ca1 to your computer and use it in GitHub Desktop.
module Main where
-- Challenge: rudimentary spam filter
-- given the sample blacklist and comments check to see if
-- the phrases in the blacklist are in the comment
import Data.List (isInfixOf)
type BlackList = [String]
type Comment = String
comment1 :: Comment
comment1 = "Collection of my foo bar"
comment2 :: Comment
comment2 = "How to get free hotel upgrades"
blackList :: BlackList
blackList =
[
"foo bar",
"baz qux quux",
"spam",
"grault garply i",
"grault garply ii"
]
inBlackList :: Comment -> BlackList -> Bool
inBlackList comment blacklist =
any (\phrase -> isInfixOf phrase comment) blacklist
main =
print
$ show
$ inBlackList comment1 blacklist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment