我想创建一个模块,并将其加载到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