Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6849545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:00:17+00:00 2026-05-27T01:00:17+00:00

I want to create a module, and load it in the haskell library. I

  • 0

I want to create a module, and load it in the haskell library. I can work with ubuntu 11, or windows 7, using the tools of the haskell-platform. This is my module:

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)

I have also some problem with “show” in the ghci, because I get an exception of stack overflow.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:00:18+00:00Added an answer on May 27, 2026 at 1:00 am

    Your paste is messing with the code; maybe it should look so: http://hpaste.org/54363 (note the advice from hlint at the bottom.) The following steps are for a simple method of development, but will I think expose most of the relevant factors:

    • Rename the module to the more sensible Poker.Elements, save it as Elements.hs

    • Make a directory named poker with a subdirectory named Poker

    • Move Elements.hs into poker/Poker. Now its hierarchical name, Poker.Elements makes sense. Your directory structure looks so:

      -- poker -- Poker -- Elements.hs 
      
    • poker is now organized properly. Type ghci Poker/Elements.hs from there and ghci will know how to deal with any other Poker.x.y.z modules in a more complicated structure like say this one:

      -- poker -- Poker -- Internal -- Guts.hs (i.e.Poker.Internal.Guts)          
                        |
                        -- Elements.hs  (i.e. Poker.Elements)
      

    But our idea was to build and install the poker library with the cabal tool. Nothing simpler.

    • cd into poker if you are not there.

    • Run cabal init. The answers will all be obvious. You are making a Library, pertaining to Games.

    • Edit your new poker.cabal file — cabal init can’t tell what packages you are using.
      In fact, you are only using Prelude and Data.Char which are in base, so extend the Build-depends line to look thus:

      Build-depends:       base > 2
      

      The result will look like this: http://hpaste.org/54364 (If you are missing any other dependencies, this will emerge with the next command.)

    • Your directory now has this structure:

      -- poker   -- poker.cabal
                |
                 -- Poker      -- Elements.hs
      
    • You thus now have a cabalized, buildable, indeed hackage-able package. Type cabal install, then cabal clean. The cabal tool has managed configuration, compilation, installation and registration of the package. (By default the compiled library will be deposited in the hidden directory $HOME/.cabal/lib/poker-0.1 or the equivalent for your system.)

    • Open ghci from anywhere on your system; type import Poker.Elements. Enjoy. It is no different if you call ghc directly — for example, if you make an executable with ghc --make -O2 PokerCalculator.hs -o pokercalculator, ghc will now know how to find Poker.Elements without further instruction.

    • Test your definitions. Reflect. Fret. Reconsider. Test more. Look into quickcheck.

    • When you revise your module, rebuild and reinstall with cabal install. This will over-write the old installation of poker-0.1, as you are still calling it; but in this, simplest, case, no other packages are being built against it so the result is desirable. (If your other experimental library, texas-holdem-0.1 — the one in the next directory –imports Poker.Elements, as is likely, then rebuild it too to use your more advanced ideas about the Elements of poker.)

    • If you add new modules, or import modules from new packages, specify these in the relevant lines of poker.cabal. If you forget, cabal install will politely remind you to do this when you try to rebuild …

    • Upload your poker package to github or patch-tag or darcsden. When you have perfected it, upload it to hackage. Note that even on github or patch-tag it belongs to the ‘hackaged’ universe. If you import modules from fancier packages on Hackage, then when people git clone or darcs get your repository, cabal install will get the right packages for them from hackage.haskell.org.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I want to use pythons built in calendar module to create an
I want to create a Java application bundle for Mac without using Mac. According
i wonder if there are tutorials/books explaining how you create a library/plugin/module for other
I want to try this module https://github.com/creationix/nstore fore simple storage . But when i
I want to create a website that offers users modules/widgets that can be dragged
I want to create an apache 2(2.2.21 to be more specific) module in Delphi
I want to create a 3D visualizer of .raw volume medical datasets using marching
I created module for admin specific operations. I don't want to write the same
I want create a drop shadow around the canvas component in flex. Technically speaking
I want create a excel with Apache POI in java and I must insert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.