[Haskell-cafe] Newbie: generating a truth table

Gene A yumagene at gmail.com
Tue Feb 20 23:46:25 EST 2007


On 2/10/07, Peter Berry <pwberry at gmail.com> wrote:
>
> Sigh, I seem to have done a reply to sender. Reposting to the list.
>
> On 06/02/07, phiroc at free.fr <phiroc at free.fr> wrote:
> > Hello,
> >
> > I would like to create a Haskell function that generates a truth table,
> for
> > all Boolean values, say, using the following "and" function :
> >
> > and :: Bool -> Bool -> Bool
> > and a b = a && b




This is solution that I used with list comprehension.. combining some of the
other ideas on the thread such as a tuple to see the original values and
then the result.

Prelude> putStrLn $ concatMap (flip (++)"\n") $ map show $ [(x,y,(&&) x y)
|x <- [True,False],y <- [True,False]]
(True,True,True)
(True,False,False)
(False,True,False)
(False,False,False)

gene
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070220/24a1dd21/attachment.htm


More information about the Haskell-Cafe mailing list