实例声明中的非法类型签名

use*_*850 10 haskell ghc

我在实例声明错误中得到非法类型签名,我不知道为什么它会弹出我的程序.缩进似乎是对的,等等.我希望你能帮助我.

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
Run Code Online (Sandbox Code Playgroud)

错误是:

Illegal type signature in instance declaration:
  findPossibleMoves :: Player -> HForest -> [(HStrategy, HForest)]
(Use InstanceSigs to allow this)
In the instance declaration for `Game HForest HStrategy'
Run Code Online (Sandbox Code Playgroud)

Rei*_*ton 14

您在实例声明中有一个类型签名.这在标准的Haskell中是非法的.您可以启用InstanceSigs扩展(放在{-# LANGUAGE InstanceSigs #-}文件顶部)以允许它.或者只是删除类型签名.