我想在Haskell98中做一些抽象,但不知道如何去做。 我想要做的是爲可能轉換爲列表的類型定義一個類。 toList :: a -> [b]
但我不知道如何定義此方法的類。我提出了以下三個想法: class ToList a b where
toList :: a -> [b]
class ToList a where
toList :: a -> [b]
cla
這個數據類型的Foldable實例是什麼樣的? data X t = X t [X t]
我嘗試這樣做: instance Foldable X where
foldMap f (X x xs) = f x `mappend` foldMap f xs
但得到這個錯誤: Occurs check: cannot construct the infinite type: a = X
class (Monoid w, Monad m) => MonadWriter w m | m -> w where
pass :: m (a,w -> w) -> m a
listen :: m a -> m (a,w)
tell :: w -> m()
上面的管道是什麼意思?該片段來自here。