I'm getting the Illegal type signature in instance declaration error and I have no idea why it is popping up for my program. Indentation seems right, etc. I hope you can help me.
class Game g s | g -> s where
findPossibleMoves :: Player -> g -> [(s,g)]
identifyWinner :: g -> Player -> Maybe Player
instance Game HForest HStrategy where
identifyWinner :: HForest -> Player -> Maybe Player
identifyWinner ts p = getWinner $ getLeaves ts
findPossibleMoves :: Player -> HForest -> [(HStrategy, HForest)]
findPossibleMoves p ts = map (\s -> (s,move s ts)) $ getStrategies p ts
The error is :
Illegal type signature in instance declaration:
findPossibleMoves :: Player -> HForest -> [(HStrategy, HForest)]
(Use InstanceSigs to allow this)
In the instance declaration for `Game HForest HStrategy'
In Haskell, you can’t write a type signature in an instance declaration, but it is sometimes convenient to do so, and the language extension InstanceSigs allows you to do so. For example:
Allow type signatures for members in instance definitions. In Haskell, you can’t write a type signature in an instance declaration, but it is sometimes convenient to do so, and the language extension InstanceSigs allows you to do so. For example:
Let’s see some of the examples of legal and illegal declarations and initializations in C. It is a legal statement because we can initialize a variable with a constant. It is an illegal statement because static variable has to be initialized by a constant but here q is not initialized with a constant.
In Haskell 98 the head of an instance declaration must be of the form C (T a1 ... an), where C is the class, T is a data type constructor, and the a1 ... an are distinct type variables.
You have a type signature in an instance declaration. That's illegal in standard Haskell. You can enable the InstanceSigs
extension (put {-# LANGUAGE InstanceSigs #-}
at the top of your file) to allow it. Or just delete the type signature.
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