Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Lab3 where
- import Data.Char
- import Data.Maybe
- data Key = Shift Char | CapsLock | Sym Char deriving (Eq, Show)
- a = [Shift 'h', Sym 'e', CapsLock, Sym 'l', Sym 'l', Shift 'o', CapsLock]
- getAlNum :: [Key] -> [Key]
- getAlNum [] = []
- getAlNum ((Shift x) : xs) = getAlNum xs
- getAlNum ((CapsLock) : xs) = getAlNum xs
- getAlNum ((Sym x) : xs) = (Sym x) : getAlNum xs
- getRaw :: [Key] -> String
- getRaw [] = ""
- getRaw ((Sym x) : xs) = x : getRaw xs
- getRaw ((Shift x) : xs) = x : getRaw xs
- getRaw ((CapsLock) : xs) = getRaw xs
- isCapsLocked' :: [Key] -> Bool -> Bool
- isCapsLocked' [] c1 = c1
- isCapsLocked' (x:xs) c1 = if (x == CapsLock) then isCapsLocked' xs (not c1) else isCapsLocked' xs c1
- isCapsLocked :: [Key] -> Bool
- isCapsLocked [] = False
- isCapsLocked (x:xs) = isCapsLocked' (x:xs) False
- getSym :: Key -> Char
- getSym (Sym x) = x
- getSym (Shift x) = x
- typCode :: Key -> Int
- typCode (Sym _) = 0
- typCode CapsLock = -1
- typCode (Shift _) = 1
- getString' :: [Key] -> Bool -> String
- getString' [] _ = ""
- getString' (x:xs) cl | ((typCode x) == -1) = getString' xs (not cl)
- | ((typCode x) == 0) = if cl then (toUpper (getSym x)) : (getString' xs cl) else (getSym x) : (getString' xs cl)
- | otherwise = if (not cl) then (toUpper(getSym x)) : (getString' xs cl) else (getSym x) : (getString' xs cl)
- getString :: [Key] -> String
- getString [] = []
- getString (x:xs) = getString' (x:xs) False
- --10
- data Zadanie = Lab String Int
- | Rgz String
- | Ref String String
- deriving (Eq, Show)
- type Plan = [(Zadanie, Maybe Int)]
- plan = [(Lab "math" 1, Just 1),(Lab "math" 2, Just 2),(Lab "math" 3, Nothing),
- (Lab "math" 4, Nothing),(Rgz "phys", Just 2),(Ref "hist" "world war 2", Just 1),(Ref "hist" "world war 3", Nothing)] :: Plan
- predmet :: Zadanie -> String
- predmet (Lab x _) = x
- predmet (Rgz x) = x
- predmet (Ref x _) = x
- getByTitle :: String -> Plan -> [Zadanie]
- getByTitle _ [] = []
- getByTitle "" _ = []
- getByTitle title (x:xs) = if title == predmet (fst x) && Nothing == snd x
- then fst x : getByTitle title xs
- else getByTitle title xs
- getReferats :: Plan -> [String]
- getReferats [] = []
- getReferats ((Lab _ _, _):xs) = getReferats xs
- getReferats ((Rgz _, _):xs) = getReferats xs
- getReferats ((Ref _ t, _):xs) = t : getReferats xs
- getRest :: Plan -> [Zadanie]
- getRest [] = []
- getRest (x:xs) = if Nothing == snd x
- then fst x : getRest xs
- else getRest xs
- getRestForWeek :: Int -> Plan -> [Zadanie]
- getRestForWeek _ [] = []
- getRestForWeek n (x:xs) = if Just n >= snd x && snd x /= Nothing then fst x : getRestForWeek n xs else getRestForWeek n xs
- getCount :: Int -> Maybe Int -> Plan -> Int
- getCount n _ [] = n
- getCount n a (x:xs) = if snd x == a
- then getCount (n+1) a xs
- else getCount n a xs;
- getNums :: Plan -> [Maybe Int]
- getNums [] = []
- getNums (x:xs) = if snd x /= Nothing then (snd x) : getNums xs else getNums xs
- getUniNums :: [Maybe Int] -> [Maybe Int]
- getUniNums [] = []
- getUniNums (x:xs) = if x `elem` xs then getUniNums xs else x : getUniNums xs
- getPlot' :: [Maybe Int] -> [(Maybe Int,Int)]
- getPlot' [] = []
- getPlot' (x:xs) = if x /= Nothing
- then(x, getCount 0 x plan) : getPlot' xs
- else getPlot' xs
- getPlot :: Plan->[(Maybe Int,Int)]
- getPlot [] = []
- getPlot (x:xs) = getPlot' (getUniNums (getNums (x:xs)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement