[Haskell-cafe] Knowledge
Luke Palmer
lrpalmer at gmail.com
Wed Dec 19 16:28:09 EST 2007
On Dec 19, 2007 7:26 PM, jlw501 <jlw501 at cs.york.ac.uk> wrote:
>
> 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?
This looks like an encoding of some philosophical problem or something. I
don't really follow. I'll comment anyway.
> contains :: Eq a => [a]->a->Bool
> contains [] e = False
> contains (x:xs) e = if x==e then True else contains xs e
contains = flip elem
> perfectcomm :: Bool
> perfectcomm = undefined
> knowself :: Bool
> knowself = undefined
Why are these 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
This case will never be reached, because you match against (x:[]) first.
> comm p ps k = if contains ps p then knowself
> else perfectcomm
And I don't understand the logic here. :-p
Luke
More information about the Haskell-Cafe
mailing list