我想創建一個模塊,並將其加載到haskell庫中。我可以使用haskell平臺的工具與Ubuntu 11或Windows 7一起工作。這是我的模塊:創建並安裝自己的模塊
module Pkr.Element(..) where
import Char
data Card = Card Int deriving (Eq)
seme :: Card -> Int
seme (Card x) = mod (div x 13) 4
label :: Card -> Int
label (Card x) = mod x 13
instance Ord Card where
(>) x y |ix == iy = False
|ix == 0 = True
|iy == 0 = False
| otherwise = (ix > iy)
where
ix = label x
iy = label y
instance Show Card where
show :: Card -> String
show card = strI(label card) : strS(seme card) :[]
where
strI x | (x == 0) = 'A'
| (x == 12) = 'K'
| (x == 11) = 'Q'
| (x == 10) = 'J'
| (x == 9) = 'T'
| otherwise = chr (49+x)
strS y | (y == 0) = 'h'
| (y == 1) = 'c'
| (y == 2) = 'd'
| (y == 3) = 's'
data Category = Null | HighCard | Copple | TwoCopple |
Tris | Straight | Flush | FullHouse |
Poker | StraightFlush deriving (Show, Eq, Ord)
type Cards = [Card]
data Rank = Rank Category Cards Cards deriving (Eq, Ord, Show)
我也有一些問題,「顯示」在ghci中,因爲我得到了堆棧溢出的異常。
讓我們看看你輸入到ghci中導致堆棧溢出異常。 – dave4420
你是否想在你的系統上安裝這個模塊,以便它可以被許多程序使用[(使用Cabal)](http://www.haskell.org/cabal/users-guide/),或者你只是想在單個程序中使用它(您只需要將模塊放在與程序主模塊相同的目錄中)? – dave4420
我在ghci上輸入: >:l Pkr.Element; >卡片4; > ***異常計算器(或類似的東西) 關於我想要的:我正在學習haskell,我想用模塊來增加代碼的模塊性。我想在我的系統上安裝這個模塊,所以我可以重新使用我的軟件包的模塊。 – optimusfrenk