1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- lenght :: [a] -> Integer
- lenght [] = 0
- lenght (x:xs) = 1 + lenght xs
- data Tree a = Leaf a | Branch (Tree a) (Tree a)
- aTree = Branch (Leaf 'a') (Branch (Leaf 'b') (Leaf 'c'))
- ones = 1 : ones
- numsFrom n = n : numsFrom (n + 1)
- fib = 1 : 1 : [a + b | (a, b) <- zip fib (tail fib)]
- data TrafficLight = Red | Yellow | Green
- instance Eq TrafficLight where
- Red == Red = True
- Yellow == Yellow = True
- Green == Green = True
- _ == _ = False
- instance Show TrafficLight where
- show Red = "The color of the semaphore is Red"
- show Yellow = "The color of the semaphore is Yellow"
- show Green = "The color of the semaphore is Green"
- data CMaybe a = CNothing | CJust Int a deriving (Show)
- instance Functor CMaybe where
- fmap f CNothing = CNothing
- fmap f (CJust counter x) = CJust (counter+1) (f x)
- applyMaybe :: Maybe a -> (a -> Maybe b) -> Maybe b
- applyMaybe Nothing _ = Nothing
- applyMaybe (Just x) f = f x
- data Clist a = CNode a (Clist a) | CEnd (Clist a)
- instance (Eq a) => Eq (Clist a) where
- CEnd _ == CEnd _ = True
- (CNode a next) == (CNode b next2) = (a==b) && next == next2
- _ == _ = False
- clist2list :: Clist a -> [a]
- clist2list (CEnd end) = []
- clist2list (CNode a next) = a : clist2list next
- list2clist :: [a] -> Clist a
- list2clist [] = let new = CEnd new
- in new
- list2clist (x:xs) = let first = CNode x $ list2clist' xs first
- in first
- list2clist' [] first = CEnd first
- list2clist' (x:xs) first = CNode x $ list2clist' xs first
- cmap :: (a -> b) -> Clist a -> Clist b
- cmap f (CNode x next) = let first = CNode (f x) $ cmap' f next first
- in first
- cmap' f (CEnd x) first = (CEnd first)
- cmap' f (CNode x next) first = CNode (f x) $ cmap' f next first
- transpose :: [[a]] -> [[a]]
- transpose [] = []
- transpose ls = let hs = map head ls
- ts = filter (not . null) $ map tail ls
- in hs : transpose ts
|