不在范围内:尝试导入新类型时,数据构造函数'Money`

时间:2018-12-23 20:52:11

标签: haskell functional-programming

我正在尝试制作RPG Atm。我创建了一个新的堆栈项目和一个文件 在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 ...并尝试导入它,但是它也没有用。

0 个答案:

没有答案
相关问题