This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {- | |
| As interesting side reading, consult https://www.reddit.com/r/haskell/comments/1m9opl/passing_list_as_arguments/ | |
| -} | |
| halve :: [a] -> ([a],[a]) | |
| halve xs = splitAt (((length xs) + 1) `div` 2) xs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| thirdHeadAndTail :: [a] -> a | |
| thirdHeadAndTail = head . tail . tail | |
| thirdIndex :: [a] -> a | |
| thirdIndex xs = xs !! 2 | |
| thirdPatternMatching :: [a] -> a | |
| thirdPatternMatching (_:_:x:_) = x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| safetailConditional :: [a] -> [a] | |
| safetailConditional xs = if null xs | |
| then [] | |
| else tail xs | |
| safetailGuarded :: [a] -> [a] | |
| safetailGuarded xs | null xs = [] | |
| | otherwise = tail xs | |
| safetailPatternMatch :: [a] -> [a] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| or1 :: Bool -> Bool -> Bool | |
| True `or1` True = True | |
| True `or1` False = True | |
| False `or1` True = True | |
| False `or1` False = True | |
| or2 :: Bool -> Bool -> Bool | |
| False `or2` False = False | |
| _ `or2` _ = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| formalConjunction :: Bool -> Bool -> Bool | |
| formalConjunction a b = | |
| if a then | |
| if b then | |
| True | |
| else False | |
| else False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| formalConjunction :: Bool -> Bool -> Bool | |
| formalConjunction a b = | |
| if a then | |
| b | |
| else | |
| False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mult :: Int -> Int -> Int -> Int | |
| mult = \x -> (\y -> (\z -> x * y * z)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| luhnDouble :: Int -> Int | |
| luhnDouble n | n <= 5 = 2 * n | |
| | otherwise = 2 * n - 9 | |
| luhn :: Int -> Int -> Int -> Int -> Bool | |
| luhn a b c d = | |
| (luhnDouble a + b + luhnDouble c + d) | |
| `mod` 10 == 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sum100ConsecSquares :: Int | |
| sum100ConsecSquares = sum [x^2 | x <- [1..100]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| grid :: Int -> Int -> [(Int,Int)] | |
| grid m n = [(x,y) | x <- [0..m], y <- [0..n]] |
OlderNewer