在实例

时间:2015-12-08 00:26:35

标签: haskell

所以我对Haskell很新,我一直试图想出如何在一个实例中使用show类型类打印出[Stat]

module HaskellGame.Datatypes where ....


   data Stat = Stat {
                     name ::String, 
                     value::Int
                    }

    data Monster = Monster {
                           name :: String,
                           stats :: [Stat]
                         }

到目前为止,我写的代码是:

   module HaskellGame.Graphics where ...

   {-This displays the Monster on the Map-}
    instance Show Monster where
     show (Monster _ _ ) = "M"
   {-This displays the stats of the monster-}
    instance Show Stat where
     show (Stat name value) = (show(name)) ++ ": " ++ (show(value))

我收到此错误:

 Couldn't match expected type `Stat'
            with actual type `([Char], Integer)'
In the expression: ("Toughness", 1)
In the second argument of `Monster', namely
  `[("Strength", 5), ("Toughness", 1)]'
In the expression:
  Monster
    "Dragon" [("Strength", 5), ("Toughness", 1)] [("Fisticuffs", 1)]

我想知道我做错了什么。

1 个答案:

答案 0 :(得分:2)

大概不是easeOutQuart(0.5, 10, 20); // t@0 returns 10 and t@1 returns 20 easeOutQuart(0.5, 40, -10); // t@0 returns 40 and t@1 returns -10 easeOutQuart(0.5, -10, 30); // t@0 returns -10 and t@1 returns 30 而是instance Show Stat,因为instance Show Monster已经有一个合适的Stat实例。