在Haskell中合并两个排序列表

Jen*_*en 5 merge haskell list

我试图在Haskell中合并两个排序列表.这两个列表必须包含相同的类型,但该函数需要采用不同类型的列表.

这就是我所拥有的(我知道我需要一些代码来避免尝试从空列表中取出元素):

merge :: Ord a => [a] -> [a] -> [a]
merge [] [] = []
merge (h:first) (c:second)  | h <= c = h:merge first (c:second)
                | h > c = c:merge (h:first) second

main = merge ['a','b','c'] ['d','e','f']
Run Code Online (Sandbox Code Playgroud)

问题是我是Haskell的新手,我得到了这个错误消息,我有点理解,但不知道要做什么:

Couldn't match expected type `IO t0' with actual type `[Char]'
In the expression: main
When checking the type of the function `main'
Run Code Online (Sandbox Code Playgroud)

有谁知道这意味着什么?非常感谢帮助!

ham*_*mar 8

main需要成为一种IO行动.如果要打印列表,请执行以下操作:

main = print $ merge ['a','b','c'] ['d','e','f']
Run Code Online (Sandbox Code Playgroud)