广义语句中的二叉树

时间:2017-05-19 09:49:22

标签: haskell

我必须实现一个接受二叉树的代码并显示一个通用语句:这是我的代码

mkBTree xs
    | (m == 0) = Leaf (unwrap xs)
| otherwise = Fork (mkBTree ys) (mkBTree zs)
where m = (length xs) `div` 2
      (ys, zs) = splitAt m xs
              unwrap [x] = x

但我唯一得到的是:

Data constructor not in scope: Leaf :: a -> t
Data constructor not in scope: Fork :: t -> t -> t

失败,模块已加载:无。 这有什么不对?

1 个答案:

答案 0 :(得分:-3)

我必须实现一个接受二叉树并显示一般化语句的代码:这是我的代码导入Data.Char        import Data.List

  data mkBTree xs = Leaf xs | Fork (mkBTree xs) xs (mkBTree xs)
  deriving(Eq,Show)

 data mkBTree xs = Leaf xs | Fork xs [mkBTree xs]
   deriving(Eq,Show)


entferneBlaetter :: NBaum a -> NBaum a
entferneBlaetter xs
             | (m == 0) = BBlatt (unwrap xs)
         | otherwise = BKnoten (NBaum ys) (NBaum zs)
         where m = (length xs) `div` 2
                (ys, zs) = splitAt m xs
                    unwrap [x] = x