Lists of data types: “could not deduce (a ~ SomeType) from the context (SomeTypeclass a)”

后端 未结 3 452
闹比i
闹比i 2021-01-03 22:52

I have the following problem with Haskell\'s type system: I am trying to declare a data type and return a list containing elements of this type from a function. Unfortunatel

3条回答
  •  误落风尘
    2021-01-03 23:18

    the offending line is stList :: (Show a) => [a]. You're declaring that stList is a polymorphic list that holds any element which satisfies the show constraint. But stList isn't a polymorphic list! It's a list of SampleTypes. So remove the signature and see what ghci infers, or just give it the correct signature: :: [SampleType].

提交回复
热议问题