typeclass

    21熱度

    4回答

    所以,我有一對,我會使用大量的一起類型類的,我想避免這兩種每次指定。基本上,而不是把 :: (Ord a, Fractional a, Ord b, Fractional b, ... Ord z, Fractional z) => 我的所有類型規範的開始,我寧願把 :: (OrdFractional a, OrdFractional b, ... OrdFractional z) 所以,

    8熱度

    3回答

    我想在Haskell98中做一些抽象,但不知道如何去做。 我想要做的是爲可能轉換爲列表的類型定義一個類。 toList :: a -> [b] 但我不知道如何定義此方法的類。我提出了以下三個想法: class ToList a b where toList :: a -> [b] class ToList a where toList :: a -> [b] cla

    1熱度

    1回答

    這個數據類型的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

    21熱度

    5回答

    我不認爲這是一個錯誤,但我有點困惑,爲什麼這是行不通的。一個額外的問題是爲什麼它提到變量e?沒有變量e。 Prelude> :m +Control.Exception Prelude Control.Exception> handle (\_-> return "err") undefined <interactive>:1:0: Ambiguous

    21熱度

    1回答

    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。