diff --git a/02-lab.hs b/02-lab.hs new file mode 100644 index 0000000..e374428 --- /dev/null +++ b/02-lab.hs @@ -0,0 +1,39 @@ +import Data.Char + +orB :: Bool -> Bool -> Bool +orB x y = x || y + +swap :: (x, y) -> (y, x) +swap (x, y) = (y, x) + +middle :: [a] -> [a] +middle x = tail (take ((length x) - 1) x) + +condrev :: [a] -> [a] +condrev x | (length x) >= 7 = reverse x + | otherwise = x + +dblmagic :: [Int] -> [Int] +dblmagic x = filter (>10) (map (*2) x) + +wtfstring :: String -> String +wtfstring x = reverse (map (toUpper) x) + +addindex :: [a] -> [(Int, a)] +addindex x = zip [0..((length x) - 1)] x + +relcmp :: (Num a, Ord a) => a -> a -> Bool +relcmp x y | x > y && x < (y*2) = True + | otherwise = False + +third :: [a] -> a +-- third x = head (tail (tail x)) +-- third x = x!!2 +third (_:_:x:_) = x + +safetail :: [a] -> [a] +-- safetail x = if (length x) == 0 then [] else tail x +-- safetail x | length x == 0 = [] +-- | otherwise = tail x +safetail [] = [] +safetail (_:xs) = xs \ No newline at end of file