我对Haskell'length'函数的重新定义将不起作用

有人可以解释一下我如何修复程序。 对于Haskell来说,这是非常新的东西,它一直试图创建一个长度函数来计算任何类型的列表的长度。

我的目标是使用“数据”来做到这一点,因为我想创建一个全新的类型来做到这一点(这是我目前正在学习的Haskell领域,这就是为什么它可能不是此功能的最有效实现) )

data List a = Nil | Cons a (List a)


len :: List a -> Int
len Nil         = 0
len (Cons _ xs) = 1 + len xs

If I run it on len [1,2,3] I get the error:

 • Couldn't match expected type ‘List a0’
                  with actual type ‘[Integer]’
    • In the first argument of ‘len’, namely ‘[1, 2, 3]’
      In the expression: len [1, 2, 3]
      In an equation for ‘it’: it = len [1, 2, 3]