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 8502779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:34:50+00:00 2026-06-11T01:34:50+00:00

If you declare a library + executable sections in a cabal file while avoiding

  • 0

If you declare a library + executable sections in a cabal file while avoiding double compilation of the library by putting the library into a hs-source-dirs directory, you cannot usually run your project with ghci and runhaskell anymore, especially if the executables have helper modules themselves.

What is a recommended project layout that

  • only builds what is needed once
  • allows using runhaskell
  • has a clean structure without hacks?
  • 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-06-11T01:34:52+00:00Added an answer on June 11, 2026 at 1:34 am

    Let’s assume you have a mylib library, and mylib-commandline and mylib-server executables.

    You use hs-source-dirs for the library and each executable so that each has their own project root, avoiding double compilation:

    mylib/                      # Project root
      mylib.cabal
      src/                      # Root for the library
      tests/
      mylib-commandline/        # Root for the command line utility + helper modules
      mylib-server/             # Root for the web service + helper modules
    

    Full directory layout:

    mylib/                      # Project root
      mylib.cabal
      src/                      # Root for the library
        Web/
          Mylib.hs              # Main library module
          Mylib/
            ModuleA             # Mylib.ModuleA
            ModuleB             # Mylib.ModuleB
      tests/
        ...
      mylib-commandline/        # Root for the command line utility
        Main.hs                 # "module Main where" stub with "main = Web.Mylib.Commandline.Main.main"
        Web/
          Mylib/
            Commandline/
              Main.hs           # CLI entry point
              Arguments.hs      # Programm command line arguments parser
      mylib-server/             # Root for the web service
        Server.hs               # "module Main where" stub with "main = Web.Mylib.Server.Main.main"
        Web/
          Mylib/
            Server/
              Main.hs           # Server entry point
              Arguments.hs      # Server command line arguments parser
    

    The stub-like entry point file mylib-commandline/Main.hs looks like this:

    module Main where
    
    import qualified Web.Mylib.Server.Main as MylibServer
    
    main :: IO ()
    main = MylibServer.main
    

    You need them because an executable must start on a module simply called Main.

    Your mylib.cabal looks like this:

    library
      hs-source-dirs:   src
      exposed-modules:
        Web.Mylib
        Web.Mylib.ModuleA
        Web.Mylib.ModuleB
      build-depends:
          base >= 4 && <= 5
        , [other dependencies of the library]
    
    executable mylib-commandline
      hs-source-dirs:   mylib-commandline
      main-is:          Main.hs
      other-modules:
        Web.Mylib.Commandline.Main
        Web.Mylib.Commandline.Arguments
      build-depends:
          base >= 4 && <= 5
        , mylib
        , [other depencencies for the CLI]
    
    executable mylib-server
      hs-source-dirs:   mylib-server
      main-is:          Server.hs
      other-modules:
        Web.Mylib.Server.Main
      build-depends:
          base >= 4 && <= 5
        , mylib
        , warp >= X.X
        , [other dependencies for the server]
    

    cabal build will build the library and the two executables without double compilation of the library, because each is in their own hs-source-dirs and the executables depend on the library.

    You can still run the executables with runghc from your project root, using the -i switch to tell where it shall look for modules (using : as separator):

    runhaskell -isrc:mylib-commandline mylib-commandline/Main.hs
    
    runhaskell -isrc:mylib-server mylib-server/Server.hs
    

    This way, you can have a clean layout, executables with helper modules, and everything still works with runhaskell/runghc and ghci. To avoid typing this flag repeatedly, you can add something similar to

    :set -isrc:mylib-commandline:mylib-server
    

    to your .ghci file.


    Note that sometimes should split your code into separate packages, e.g. mylib, mylib-commandline and mylib-server.

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

Sidebar

Related Questions

I'm using iTextsharp library to create PDF files. I can declare for A4 Landscape
DECLARE @table table(XYZ VARCHAR(8) , id int) INSERT INTO @table SELECT '4000', 1 UNION
I need to have an executable file (.exe) which takes some parameters from a
Why does Flash still offer to declare library items as either MovieClip, Graphic or
Following this post (I was looking for a library allowing me to declare Django
In the standard library (glibc) I see functions defined with leading double underscores, such
I am currently using JetBrains WebStorm to develop a JavaScript library. When I declare
I'm using something similar to example C on this MSDN page: http://msdn.microsoft.com/en-us/library/ms190307.aspx DECLARE @tableHTML
In *.h header files of a C library, should one declare functions extern void
I'm using the library STPrivilegedTask library, source found at http://www.sveinbjorn.org/STPrivilegedTask to run the NSTask

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.