需要帮助调用 Haskell 函数,该函数的参数涉及本身采用参数的类型



抱歉,如果标题不明确,本质上我有以下数据类型声明:

type Domino = (Integer, Integer)
type Hand = [Domino]
type Board = [Domino]
type DomsPlayer = Hand -> Board -> (Domino, End)
type Score = (Integer, String)

和一个函数:

playDomsRound :: DomsPlayer -> DomsPlayer -> Int -> (Score, Score)

如何调用 playDomsRound 函数?

Haskell中类型化应用程序的基本规则非常简单,

f    :: a  -> b   ===
f (x :: a) :: b

因此,在您的情况下,

playDomsRound    :: DomsPlayer     -> DomsPlayer     -> Int  -> (Score, Score)   ===
playDomsRound (p :: DomsPlayer)    :: DomsPlayer     -> Int  -> (Score, Score)   ===
playDomsRound (p :: DomsPlayer) (q :: DomsPlayer)    :: Int  -> (Score, Score)   ===
playDomsRound (p :: DomsPlayer) (q :: DomsPlayer) (i :: Int) :: (Score, Score)

您可以在代码中编写上述任何内容。

任何具有类型的表达式都可以出现在代码中。

既然你已经定义了

type DomsPlayer = Hand -> Board -> (Domino, End)

类型DomsPlayer与类型Hand -> Board -> (Domino, End)相同。这就是您的playDomsRound所期望的:一个函数。尚未应用于期望的任何参数。只是一个函数。

最新更新