由于类型错误,无法实现可折叠实例

问题描述 投票:1回答:1

我正在学习haskell,并试图制作一个漂亮的打印程序。在某个时候,我想获取一行的长度(即该行中的列数)。为了能够对我的数据类型执行此操作,我了解我必须实现依赖于Monoid的Foldable。

以前,我的行只是列表的类型别名,但是为了学习,我想采取这一行动

    import System.IO
    import System.Directory
    import Control.Monad
    import Data.Maybe
    import Data.Monoid
    import Data.Foldable
    import Data.Functor
    import Data.List.Split

    type Field = String
    data Row = Row [Field]

    instance Monoid Row where
        mempty = Row []


    instance Foldable Row where
        foldMap f (Row fs) = foldMap f fs

但是我收到以下编译器错误(在ghci 8.0.2上)

main.hs:20:19: error:
    • Expected kind ‘* -> *’, but ‘Row’ has kind ‘*’
    • In the first argument of ‘Foldable’, namely ‘Row’
      In the instance declaration for ‘Foldable Row’

现在,我不熟悉数据类型的类型。我原以为这会简单地归因于Row的List []类型的唯一属性。

我正在学习haskell,并试图制作一个漂亮的打印程序。在某个时候,我想获取一行的长度(即该行中的列数)。为了能够在我的数据类型上做到这一点,我理解...

haskell ghc foldable
1个回答
0
投票

[当我们有Foldable T时,T必须是parametric

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.