12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <<<<<<< HEAD
- 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
- =======
- module Haskell4 where
- import Control.Applicative
- import Control.Monad
- exmon :: (Monad m, Num r) => m r -> m r -> m r
- exmon m1 m2 = do x <- m1
- y <- m2
- return $ x-y
- main = exmon (do putStr "?> "
- x <- getLine;
- return (read x :: Int))
- (return 10)
- >>>>>>> 66d23fcd2717ce0805f5442c6cf4888114f9b38c
|