First program i’m writing while reading various Haskell tutorials gives me a “Kind mis-match” error
import qualified Data.Vector as V
class SupervisedLearner l where
learn :: l (Input n) -> Output n
data Input n = Supervised (V.Vector n ,V.Vector n) | Unsupervised (V.Vector n)
data Output n = Regression n | KClass (V.Vector n) | Bernoulli (n, n)
newtype Perceptron = Perceptron (V.Vector Float)
instance SupervisedLearner Perceptron where
learn = undefined
What’s confusing me is when i try to follow the type signature of the error,
Kind mis-match
The first argument of `SupervisedLearner' should have kind `*
-> *',
but `Perceptron' has kind `*'
In the instance declaration for `SupervisedLearner Perceptron'
I just can’t seem to understand where I should look to even begin to correct it.
So my question is two fold, where is the error, and a generally sense, am I using the Haskell typeclass system correctly?
According to your class definition, you need to define a method
learnof typel (Input n) -> Output nto makelan instance ofSupervisedLearner. So to make Perceptron an instance ofSupervisedLearner,learnwould have to have the typePerceptron (Input n) -> Output n.But the
Perceptrontype doesn’t take any type arguments, soPerceptron (Input n)is not a valid type. That’s what the error message is complaining about (kind*means that a type doesn’t take any type arguments and kind* -> *means that a type takes one type argument).