私はtreeの定義をfunctorとfoldableのインスタンスにするよう求めているhw問題のコードを少し書いています。私は以下のコードを記述する場合:functorとfoldableのインスタンスとしてのツリー
import Data.Foldable
import Data.Monoid
data Tree a = Leaf a
| Node [Tree a]
deriving (Show)
instance Functor (Tree) where
fmap f (Leaf a) = Leaf (f a)
fmap f (Node [Tree a]) = fmap f [Tree a]
instance Foldable (Tree) where
foldMap f (Leaf a) = f a
foldMap f (Node [Tree a]) = foldMap f `mappend` [Tree a]
を次のエラーが表示されます
私は間違っているつもりですhw.hs:10:19:
Not in scope: data constructor `Tree'
Perhaps you meant `True' (imported from Prelude)
hw.hs:10:38:
Not in scope: data constructor `Tree'
Perhaps you meant `True' (imported from Prelude)
hw.hs:14:22:
Not in scope: data constructor `Tree'
Perhaps you meant `True' (imported from Prelude)
hw.hs:14:54:
Not in scope: data constructor `Tree'
Perhaps you meant `True' (imported from Prelude)
Failed, modules loaded: none.
?
ありがとうございます!
[[更新]]
私は以下の回答で作られた提案ごとにコードに変更を加えました。エラーのあるコードへのリンクがあります。もし誰かがそれを見て、私が間違っている場所を教えてくれれば素晴らしいだろう。
おかげで再び!
技術的には、 'Tree'はコンストラクタの一種です。型コンストラクタです。だから、値を作る型とノードを作る。 – jozefg
@jozefgややこしい!しかし、大丈夫、私はそれを変更しました:) –
@PeterHallありがとう!あなたの提案に応じてコードを変更しましたが、まだエラーメッセージが表示されます エラーメッセージmsg: http://snipt.org/Bahjg5 – user2994154