
Hi
On 5/14/07, Veer Singh
Hello, I am trying to learn haskell , but i am struggling with types , its been around 7 days , it will be very kind if some explain it why this error , i think this is the only stumbling block . I am looking for the comparison on why similar code works , while other code not .
I get this error on ghci : {- `a' is not applied to enough type arguments Expected kind `*', but `a' has kind `* -> *' In the type `SS a' In the type `(Monad a) => {Monad (SS a)}' In the instance declaration for `Monad (SS a)' -}
Here is the very small code with comments:
data SS a = SS a Int data Maybe1 a = Nothing1 | Just1 a
instance Monad Maybe1 where (Just1 x) >>= f = f x
--^^ this loads fine in ghci
-- where as this instance (Monad a)=> Monad (SS a) where (SS x y) >>= f = f (x y)
--^^ does not work , so whats the difference , both have type parameters
-- something similar works like this : instance (Eq a)=>Eq (SS a) where (SS x y) == (SS b c) = (y == c) && (x == b)
The problem is that you've overspecified the monad SS. Notice that you only had to write instance Monad Maybe1 not instance Monad (Maybe1 a) That's because you declared Maybe1 to only take in one type parameter. SS also takes in only one type parameter, so you're actually telling it that it should make SS a b into a monad, but there is no SS a b. It might help to look at the definition of the State monad in All About Monads http://www.haskell.org/all_about_monads/html/ You'll see that state is defined as newtype State s a =... and they declare instance Monad (State s) not instance Monad (State s a)