I've accidentally discovered that the following is a perfectly compiling code:
class SomeClass a
someValue :: Maybe (SomeClass a)
someValue = undefined
I'm only used to seeing classes in type constraints, so I don't understand why this code typechecks and what's the purpose of using classes that way.
I'm on GHC 7.6.2.
A type parameter, also known as a type variable, is an identifier that specifies a generic type name. The type parameters can be used to declare the return type and act as placeholders for the types of the arguments passed to the generic method, which are known as actual type arguments.
Parameter Types We can use any data type such as primitive data types including int, float, double, char, short, byte, String, and object reference variables for a parameter of a method and constructor. There is no standard limit to specify the number of parameters in the definition of a method.
Type Parameter Naming Conventions The most commonly used type parameter names are: E - Element (used extensively by the Java Collections Framework) K - Key. N - Number.
The type parameter is a placeholder for a specific type that the client specifies when they create an instance of the generic type. A generic class cannot be used as-is because it is simply a blueprint for that type.
It's a bug in ghc-7.6.2. It should be a kind error. Please report it.
Error.
A.hs:3:21: Class `SomeClass' used as a type
In the type signature for `someValue':
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With