Search code examples
haskellghctype-signature

GHC - constraint in type signature invalid


I'm trying to load the following definition

data NestedList a = Elem a | List [NestedList a]
flatten :: (NestedList a) => a -> [a]
flatten (Elem x) = [x]

But GHC is giving an error

Expected a constraint, but 'NestedList a' has kind '*'
In the type signature for 'flatten'

Is there something missing or invalid in the type signature?

Thanks in advance


Solution

  • The part before => is a constraint and must contain type classes, while NestedList is just a type. What you wanted to write is

    flatten :: NestedList a -> [a]