I am beginner level of the Haskell Language and I was trying to implement Insertion Sort function in Haskell in ghci environment.
here's my code.
prelude> let insert x [] = x:[]
insert :: t1 -> [t] -> [t1]
prelude> let insert x (y:ys) =
if x < y then x:y:ys else y : insert ys
insert :: Ord a => a -> [a] -> [a]
I tried
insert 1 []
the result was [1], It worked well.
and I tried
insert 1 ([2,3])
the result was [1,2,3], Still it works well.
(Actually, I don't know why I have to parse on second argument list. but if I try insert 1 [2,3], it doesn't work.)
it worked well until this. but when I tried
insert 4 ([1,2,3])
It happened like this.
[1,2,3*** Exception: <interactive>:165:5-61: Non-exhaustive patterns in function
I don't why it did happen like this.please help me.