**Paste:**#108272**Author:**1HaskellADay**Language:**Haskell**Channel:**-**Created:**2014-07-28 11:38:26 UTC**Revisions:**- 2014-07-28 17:11:56 UTC #108297 (diff): No title (1HaskellADay)
- 2014-07-28 11:38:26 UTC #108272: Boole, George Boole, at your service (1HaskellADay)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | module Control.Boolean where import Prelude hiding (and, or, not) {-- Okay, so I guess we are doing this thing. From the P-99 Prolog problem set we are looking at P46 through P48: define truth tables for and, or, nand, nor, xor, impl, equ, and not. There's a twist to this problem, however: You only have one, count'm: one, operator in the base language from which you define all the other operators, so choose wisely. --} and, or, nand, nor, xor, impl, equ :: Bool -> Bool -> Bool and a b = undefined or a b = undefined nand a b = undefined nor a b = undefined xor a b = undefined impl a b = undefined equ a b = undefined not :: Bool -> Bool not a = undefined {-- AND THEN, once you've defined your operators, define a function, table, that returns a table of truth values for an input expression: --} table :: [[Bool]] -> ([Bool] -> Bool) -> [Bool] table truths fn = undefined {-- So, you get something like this: table([[True, True], [True, False], [False, True], [False, False]], \a b -> and a (or a b)) ~> [True, True, False, False] I suppose it is possible to use list-compression to ensure full coverage of inputs, if one were so inclined to do that. A little bit of history from wikipedia: Boole's work and that of later logicians initially appeared to have no engineering uses. Claude Shannon attended a philosophy class at the University of Michigan which introduced him to Boole's studies. Shannon recognised that Boole's work could form the basis of mechanisms and processes in the real world and that it was therefore highly relevant. In 1937 Shannon went on to write a master's thesis, at the Massachusetts Institute of Technology, in which he showed how Boolean algebra could optimise the design of systems of electromechanical relays then used in telephone routing switches. He also proved that circuits with relays could solve Boolean algebra problems. Employing the properties of electrical switches to process logic is the basic concept that underlies all modern electronic digital computers. Victor Shestakov at Moscow State University (1907–1987) proposed a theory of electric switches based on Boolean logic even earlier than Claude Shannon in 1935 on the testimony of Soviet logicians and mathematicians Yanovskaya, Gaaze-Rapoport, Dobrushin, Lupanov, Medvedev and Uspensky, though they presented their academic theses in the same year, 1938.[clarification needed] But the first publication of Shestakov's result took place only in 1941 (in Russian). Hence Boolean algebra became the foundation of practical digital circuit design; and Boole, via Shannon and Shestakov, provided the theoretical grounding for the Digital Age.[34] https://en.wikipedia.org/wiki/George_Boole A solution is available at http://lpaste.net/108295 --} |