Knowledge
I'm new to functional programming and Haskell and I love its expressive ability! I've been trying to formalize the following function for time. Given people and a piece of information, can all people know the same thing? Anyway, this is just a bit of fun... but can anyone help me reduce it or talk about strictness and junk as I'd like to make a blog on it?
contains :: Eq a => [a]->a->Bool
contains [] e = False
contains (x:xs) e = if x==e then True else contains xs e
perfectcomm :: Bool
perfectcomm = undefined
knowself :: Bool
knowself = undefined
allKnow :: Eq a => [a]->String->Bool
allKnow _ "" = True
allKnow [] k = False
allKnow (x:[]) k = knowself
allKnow (x:xs) k =
comm x xs k && allKnow xs k
where
comm p [] k = False
comm p ps k = if contains ps p then knowself
else perfectcomm