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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:58:40+00:00 2026-06-04T18:58:40+00:00

I’m trying to solve an algorithm puzzle in Haskell, and to do so I

  • 0

I’m trying to solve an algorithm puzzle in Haskell, and to do so I need quite a big data structure. However the problem solving site I submit my solution to, doesn’t use any run time options to allow bigger stack, but I’ve heard that I can use compiler options as pragma. I’ve tried using following pragma in my code:

{-# OPTIONS_GHC -O2 -rtsopts -with-rtsopts=-K32m #-}

Then I compile with ghc --make algo.hs. However, when I run on my machine on some big tests, program crashes with stack overflow, and reports that current stack size is 8MB. On the other hand, when I compile like that:

ghc -rtsopts -with-rtsopts=-K32M --make algo.hs -fforce-recomp

The program works just fine on the same data, without adding any +RTS arguments. I use GHC 7.0.2, but the problem solving site is using 6.12.3, so preferably I’m looking for solution that could work with that old version too.

  • 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-04T18:58:40+00:00Added an answer on June 4, 2026 at 6:58 pm

    Remember that the compilation of almost any kind of native binary consists of at least two steps: Actual object compilation (.hs -> .o), and linking (.o, .a, .lib -> executable/.exe/.so/.dll etc)

    When you compile with this:

    ghc -rtsopts -with-rtsopts=-K32M --make algo.hs -fforce-recomp
    

    … what’s actually happening behind the scenes is basically:

    # object compilation - creates algo.o
    ghc -c algo.hs -fforce-recomp
    # linking - links together algo.o and libHSsomepackage.a into the "algo" binary
    # (we assume that `algo.hs` included some module from the package `somepackage`
    #  e.g. `Data.Package.Some`)
    ghc -rtsopts -with-rtsopts=-K32M -o algo -package somepackage algo.o
    

    I.e. the --make option tells GHC to compile object files automatically before linking the result, and it fills in a ton of blanks for you. Take note of where the individual command-line flags end up.

    When you specify that pragma at the top of the file, this is instead what happens (with ghc --make algo.hs):

    ghc -c algo.hs -rtsopts -with-rtsopts=-K32M
    ghc -o algo -package somepackage algo.o
    

    The OPTIONS_GHC pragma tells the compiler about options to add when compiling that specific module into an object file. Because -rtsopts is a linker option (it tells GHC to link in a different set of command-line handling stuff), you can’t specify it when compiling an object file. You must specify it when linking, and such options cannot be specified in a module header.

    There are two solutions:

    1. Use Cabal to build stuff for you and specify in your .cabal file what GHC options you want
    2. Fix your algorithm so that you don’t need as much stack space, for example by using tail recursion and more strictness in folds. See the wiki for more info.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.