Reputation: 91
Here is my code how can I say where n is int between 2..10
data Rank = Numeric Integer | Jack | Queen | King | Ace
deriving (Eq, Show)
valueRank :: Rank ->Integer
valueRank rank
|rank ==Jack = 10
|rank ==King = 10
|rank ==Queen = 10
|rank ==Ace = 10
|rank == Numeric n = n
where n =[x|x<-[2..10]]
Upvotes: 0
Views: 866
Reputation: 1749
I suggest you use pattern matching instead of guards:
valueRank :: Rank -> Integer
valueRank Jack = 10
valueRank King = 10
valueRank Queen = 10
valueRank Ace = 10
valueRank (Numeric n) = n
If you want to make sure that a Numeric can't be created with a value outside of certain range, then when making a rank you should use a smart constructor
that validates this property:
makeRank n
| 1 <= n <= 13 = ...
| otherwise = error ...
Upvotes: 6