Skip to content

Instantly share code, notes, and snippets.

@rajanikantchirmade
Created August 31, 2017 06:56
Show Gist options
  • Save rajanikantchirmade/6e7e0fc84ea3d1c3003f1ed753ddaa8c to your computer and use it in GitHub Desktop.
Save rajanikantchirmade/6e7e0fc84ea3d1c3003f1ed753ddaa8c to your computer and use it in GitHub Desktop.
insert element at given position
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
print $ myinsertAt 11 [1..6] 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment