src/Money.hs
中
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Money (Money) where
newtype Money = Money { unMoney :: Double } deriving (Show, Eq, Num)
现在我正在尝试将其导入src/Unit.hs
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
module Unit (Unit, Player, attack) where
import Data.Text (Text)
import Control.Lens
import Money
import Item (Item)
data Unit = Unit { _health :: Int
, _attackDamage :: Int
} deriving (Show, Eq)
makeLenses ''Unit
data Player = Player { _name :: String
, _stats :: Unit
, _money :: Money
} deriving (Show, Eq)
makeLenses ''Player
attack :: Int -> Unit -> Unit
attack damageTaken = health -~ damageTaken
type Attacker = Unit
type Defender = Unit
battle :: Attacker -> Defender -> (Attacker, Defender)
battle u1 u2 = (attacker, defender)
where
attacker = attack (u2 ^. attackDamage) u1
defender = attack (u1 ^. attackDamage) u2
emptyWallet :: Money
emptyWallet = Money { unMoney = 0 }
但是我得到标题中提到的错误。
我不知道我在做什么错?我还尝试将newtype Money = Money ...
更改为newtype MoneyM = MoneyM ...
并尝试导入它,但是它也没有用。