Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- factors n = [i | i <-[1..n], n `mod` i ==0 ]
- isPrime n = factors n == [1,n]
- primes =[n| n<-[2,3..], isPrime n == True]
- nPrimes n = take n primes
- sum' [] =0
- sum' (x:xs) = x + sum' xs
- multiply [] = 1
- multiply (x:xs) = x * multiply xs
- c 1 = 1
- c n = 1+2* c (n-1)
- listC = [c n | n<- [1..15]]
- lisCN n =[c i | i <- [1..n]]
- c1000 = takeWhile (<1000) [c n | n <- [1..]]
- --Ex.4
- firstFromList [] = error "Empty list :) Be carefull"
- firstFromList (x:_) = x -- key not only characters, give the type of declaration ... not general~, for the Second from the list
- secondFromList ::[a] -> a
- secondFromList [] = error "Empty!!!!"
- secondFromList [_] = error "Only one"
- secondFromList (_:x:_) = x
- lastFromList :: [a]-> a
- lastFromList [] = error "Empty list!"
- lastFromList [x] = x
- lastFromList (x:xs) = lastFromList xs
- {--
- 5 - Define a function
- mergeLists :: [[a]] -> [a]
- which returns the combined list of lists of any elements.
- For example:
- mergeLists [[1,2,3],[4,8],[9]]
- returns the list [1,2,3,4,8,9].
- mergeLists :: [[a]] -> [a]
- mergeLists x = concat x
- above good!
- megelist
- mergeLists xs ++ [] = xs
- mergeList xs
- --}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement