Difference between revisions of "FP Laboratory 6"
Jump to navigation
Jump to search
Line 2: | Line 2: | ||
*Define following functions that performs corresponding logic operations: <code>not', and', or', nand', xor', impl', equ'</code> | *Define following functions that performs corresponding logic operations: <code>not', and', or', nand', xor', impl', equ'</code> | ||
*Define the 'standard' priority for all these functions, if they are used as operators. | *Define the 'standard' priority for all these functions, if they are used as operators. | ||
− | *Create a function that | + | *Create a function that prints the truth table of a given logical expression for two variables. |
− | <syntaxhighlight lang="Haskell"> | + | <syntaxhighlight lang="Haskell">table :: (Bool -> Bool -> Bool) -> IO ()</syntaxhighlight> |
+ | <syntaxhighlight lang="Haskell" class="myDark"> | ||
+ | table (\a b -> (and' a (or' a b))) | ||
+ | True True True | ||
+ | True False True | ||
+ | False True False | ||
+ | False False False | ||
+ | </syntaxhighlight> | ||
== Complex function - Huffman Codes == | == Complex function - Huffman Codes == |
Revision as of 11:28, 18 September 2019
Operators
- Define following functions that performs corresponding logic operations:
not', and', or', nand', xor', impl', equ'
- Define the 'standard' priority for all these functions, if they are used as operators.
- Create a function that prints the truth table of a given logical expression for two variables.
table :: (Bool -> Bool -> Bool) -> IO ()
table (\a b -> (and' a (or' a b)))
True True True
True False True
False True False
False False False
Complex function - Huffman Codes
- Create a function that will compute Huffman codes for a given list of characters and their frequencies.
huffman :: [(Char, Int)] -> [(Char, String)]
*Main> huffman [('a',45),('b',13),('c',12),('d',16),('e',9),('f',5)]
[('a',"0"),('b',"101"),('c',"100"),('d',"111"),('e',"1101"),('f',"1100")]