I would like to have a function that checks a property of a class instance:
class ListWithAtLeastOneElement a where
list :: [a]
check :: Bool
check = (length list) >= 1
but I get this error when compiling in GHC:
“The class method ‘check’ mentions none of the type variables of the class ListWithAtLeastOneElement a When checking the class method: check :: Bool In the class declaration for ‘ListWithAtLeastOneElement'”
Is there a better way of doing what I want, or a way to get this to compile in GHC?
You seem to think a class in Haskell is like a class in an OO-language. That is not true. You should use a data type or newtype or type synonym.