我正在递归的Haskell中创建合并排序函数。有人告诉我,我的评估的一部分,我必须定义类型为:Haskell - Ord类型是什么意思?
isort :: Ord a => [a] -> [a]
我假定该函数需要一个数组作为输入和输出数组。我知道ord
是一类。
在上述背景下Ord a
是什么意思?
这是我的函数:
isort :: Ord a => [a] -> [a]
isort [x] = [x]
isort (x:xs) = insert x (isort xs)
where
insert :: Int -> [Int] -> [Int]
insert a [] = []
insert a (b:c) | a < b = a:b:c
| otherwise = b : insert a c
当我尝试加载我的函数文件到ghci中我得到的错误:
Couldn't match type ‘a’ with ‘Int’
‘a’ is a rigid type variable bound by
the type signature for isort :: Ord a => [a] -> [a]
at LabSheet2.hs:17:10
Expected type: [a]
Actual type: [Int]
...
尝试在最后三行上重命名'a'? – Jacob
这里没有阵列。 '[a]'是一个* list *类型。 – dfeuer