I feel very limited with those strict type errors and crazy rules; in imperative languages I feel more freedom...

import Data.List import Data.Maybe myList = do let x = "d" let lst = ["a", "b", "c", x] lst ++ ["e"] excludedList = [1..10] f::Int -> Maybe Int f x = if x `elem` excludedList then Nothing else Just x deleteAtIndex :: Int -> [a] -> [a] deleteAtIndex i lst = do let z = splitAt (i + 1) lst x = init $ fst z y = snd z x ++ y insertAtIndex :: Int -> [a] -> [a] -> [a] insertAtIndex i lst s = do let z = splitAt (i + 1) lst x = (fst z) ++ s y = snd z x ++ y ------------------------------------------------ replaceAtIndex :: Eq a => a -> [a] -> [a] -> [a] replaceAtIndex toReplace lst newNmr = do let i = elemIndex toReplace lst case i of Just i -> {- let z = splitAt i lst in z let x = fst z in x let y = snd z in y -} let z = splitAt i lst x = fst z y = snd z in do init $ fst x x ++ newNmr x ++ y Nothing -> Nothing {- init $ fst x x ++ newNmr x ++ y -} main = do putStrLn $ show myList putStrLn $ show $ f 15 let anotherList = ["a", "b", "c", "d"] putStr $ unlines anotherList mapM putStr anotherList putStrLn "\n\n\n\n\n" putStr $ unlines myList putStrLn "\n\n\n\n\n" let testLst1 = [1..25] putStrLn $ show $ deleteAtIndex 10 testLst1 putStrLn $ show $ insertAtIndex 15 testLst1 [12345] putStrLn $ show $ replaceAtIndex 5 testLst1 [3]

Error:

Quote

* Couldn't match expected type `([a0], b0)' with actual type `[a]'

* In the first argument of `fst', namely `x'

In the second argument of `($)', namely `fst x'

In a stmt of a 'do' block: init $ fst x

* Relevant bindings include

y :: [a] (bound at C:\users\niel\desktop\test2.hs:46:17)

x :: [a] (bound at C:\users\niel\desktop\test2.hs:45:17)

z :: ([a], [a]) (bound at C:\users\niel\desktop\test2.hs:44:17)

newNmr :: [a] (bound at C:\users\niel\desktop\test2.hs:34:30)

lst :: [a] (bound at C:\users\niel\desktop\test2.hs:34:26)

toReplace :: a (bound at C:\users\niel\desktop\test2.hs:34:16)

(Some bindings suppressed; use -fmax-relevant-binds=N or -fno-max-relevant-binds)

C:\users\niel\desktop\test2.hs:52:20: error:

* Couldn't match expected type `[a]' with actual type `Maybe a1'

* In the expression: Nothing

In a case alternative: Nothing -> Nothing

In a stmt of a 'do' block:

case i of {

Just i

-> let

z = ...

....

in

do { init $ fst x;

.... }

Nothing -> Nothing }

* Relevant bindings include

newNmr :: [a] (bound at C:\users\niel\desktop\test2.hs:34:30)

lst :: [a] (bound at C:\users\niel\desktop\test2.hs:34:26)

toReplace :: a (bound at C:\users\niel\desktop\test2.hs:34:16)

replaceAtIndex :: a -> [a] -> [a] -> [a]

(bound at C:\users\niel\desktop\test2.hs:34:1)