我遇到了一个我不明白的错误问题
代码:
mergHufffman::(String,Int) -> (String,Int) -> (String,Int)
mergHufffman x y = (fst x ++ fst y, snd x + snd y)
data HTree a = Leaf a | Branch (HTree a) (HTree a) deriving Show
treeHuff::[(String,Int)] -> HTree
treeHuff (x:[]) = Leaf x
treeHuff (x:y:[])
| snd x < snd y = Branch Leaf x Leaf y
| snd x > snd y = Branch Leaf y Leaf x
treeHuff (x:y:z:list)
| snd x > snd merged = Branch (Leaf x) (treeHuff y:z:list)
| otherwise = Branch (treeHuff y:z:[]) (treeHuff x:list)
where merged = mergHufffman y z
错误:
Expecting one more argument to ‘HTree’
Expected a type, but ‘HTree’ has kind ‘* -> *’
In the type signature for ‘treeHuff’:
treeHuff :: [(String, Int)] -> HTree
如果可能的话,你可以解释错误,以及我做错的地方。
解决方案:
感谢Sepp2k和Carsten,我解决了这个问题。
mergHufffman::(String,Int) -> (String,Int) -> (String,Int)
mergHufffman x y = (fst x ++ fst y, snd x + snd y)
data HTree a = Leaf a | Branch (HTree a) (HTree a) deriving Show
treeHuff::[(String,Int)] -> HTree (String,Int)
treeHuff (x:[]) = Leaf x
treeHuff (x:y:[])
| snd x < snd y = Branch (Leaf x) (Leaf y)
| snd x > snd y = Branch (Leaf y) (Leaf x)
treeHuff (x:y:z:list)
| snd x > snd merged = Branch (Leaf x) (treeHuff $ sortFirst $ y:z:list)
| otherwise = Branch (treeHuff $ y:z:[]) (treeHuff $ sortFirst $ x:list)
where merged = mergHufffman y z
sortFirst::[(String,Int)]->[(String,Int)]
sortFirst freq = reverse $ sortBy (comparing snd) freq
readHuffTree :: HTree (String,Int)-> String -> [(String, String)]
readHuffTree (Branch x y) code = f1 ++ f2
where
f1 = readHuffTree x (code ++ "0")
f2 = readHuffTree y (code ++ "1")
readHuffTree (Leaf x) code = ((fst x, code):[])
答案 0 :(得分:7)
错误消息告诉您INSERT IGNORE INTO product_categories (product_id, category_id)
VALUES (SELECT id FROM product WHERE title = ?), ?)
不是类型,除非再给它一个参数。那是HTree
或HTree String
类型,但HTree Int
本身不是。
另一种说法:当你说“我想要一棵树”时,Haskell会问“一棵树是什么?”。