This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myinsertAt :: (Num a, Eq a, Ord a) => a -> [a] -> a -> [a] | |
myinsertAt e [] p | p > 1 = error "Position out of bound." | |
myinsertAt e xs 1 = [e] ++ xs | |
myinsertAt e (x:xs) p = [x] ++ myinsertAt e xs (p-1) | |
main = do | |
let l = [1..6] | |
print $ myinsertAt 11 [] 1 | |
print $ myinsertAt 11 [1..6] 1 | |
print $ myinsertAt 11 [1..6] 3 | |
print $ myinsertAt 11 [1..6] 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
listsum :: [a] -> a | |
listsum [] = 0 | |
listsum (x:xs) = x + listsum xs | |
main = do | |
let l = [1,2,3,4,5] | |
print $ listsum l |