Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sumPositiveOnList [] = 0
- sumPositiveOnList (x:xs) = (if x>0 then x else 0) + sumPositiveOnList xs
- sumPositiveOnList' x = sum (filter (>0) x)
- -- $ is for compose function and substitute the ( ), example
- -- f1 (f2 (5*x))
- -- compose f1*f2 $ 5*x
- -- f1*f2 $ 5 *x , and for cutting $ sign for cutting
- sumPositiveOnList2 x = sum $ filter (>0) x
- --2
- count :: Num p => (t -> Bool) -> [t] -> p
- count _ [] = 0
- count f (x:xs) = (if f x == True then 1 else 0) + count f xs
- count' f (x:xs) = length $ filter f x -- or bracket way, without it , it's don't compile
- --count f (x:xs) = length $ filter f x, says: Multiple declarations of `count'
- --3
- num2 = do
- putStr "a = "
- a <- getLine
- putStr "b = "
- b <- getLine
- putStrLn $ "a+b = "++ a ++ "+" ++ b ++ "=" ++show((read a :: Double)+(read b::Double))
- --4
- --sn _ "" = ""
- sN n s
- | n < 0 = "Invalid value of n"
- | n==0 = ""
- | otherwise = s ++ " " ++ sN (n-1) s
- sns = do
- putStr "Give me a number n: "
- n <- getLine
- putStr "Type a string: "
- s <- getLine
- putStr $ sN (read n::Integer) s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement