19 Dec 20:24
Knowledge
From: jlw501 <jlw501 <at> cs.york.ac.uk>
Subject: Knowledge
Newsgroups: gmane.comp.lang.haskell.cafe
Date: 2007-12-19 19:26:08 GMT
Subject: Knowledge
Newsgroups: gmane.comp.lang.haskell.cafe
Date: 2007-12-19 19:26:08 GMT
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
--
--
View this message in context: http://www.nabble.com/Knowledge-tp14423007p14423007.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
RSS Feed