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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:55:04+00:00 2026-05-31T17:55:04+00:00

I’d like to create a Haskell app with a .NET gui. I’d like to

  • 0

I’d like to create a Haskell app with a .NET gui. I’d like to use cabal as my build tool to take advantage of it’s package management etc. I think the Haskell part should be the executable that calls into the .NET code as:

  1. This avoids having to manually initialize the Haskell RTC as described here: http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/win32-dlls.html

  2. cabal cannot easily produce Windows dlls: http://www.haskell.org/haskellwiki/Cabal/Developer-FAQ#Building_DLLs__with_Cabal

I’ve found it fairly easy to create a Haskell executable that call’s .NET using hs-dotnet, but I also need my GUI code to call back into Haskell. I was hoping to achieve this using Haskell’s “foreign export” command, then call this exported function via .NET native interop. However the “foreign export” function doesn’t seem to create an entry point in the executable, I can’t see the entry point when I do dumpbin /EXPORTS on the resulting executable. I’m not sure whether this is because GHC only create’s entry point’s when creating a dll via the -shared switch or whether cabal add a flag that suppresses entry point creation.

So I guess the question is how do I force GHC to create entry points in my Windows executable? Or would I be better using a .NET executable going though the necessary steps to create a Haskell dll with cabal and manually initializing the Haskell RTC?

  • 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-31T17:55:06+00:00Added an answer on May 31, 2026 at 5:55 pm

    I usually solve this by passing callbacks as function pointers. For example, I have an app where pressing a button needs to call back into Haskell (I’m using Cocoa, but except for the names it’s very similar).

    First, I subclass an NSButton object, and give my new ButtonC class a private member of type void(*onClickCallback)(). I also declare a function void setClickCallback(ButtonC *button, void(*callback)()); Implement your subclass so that whenever the button is clicked, the function pointer is called. In .Net, there may be a clever way to do this with delegates (it’s been a while since I’ve used .Net).

    Next, my Haskell binding looks like this (some code omitted):

    module Foreign.Button where
    
    data ButtonObj
    type ButtonPtr = ForeignPtr ButtonObj
    
    foreign import ccall unsafe "setClickCallback"
      c_setClickCallback :: Ptr ButtonObj -> FunPtr (IO ()) -> IO ()
    
    foreign import ccall "wrapper"
      makeClickCallback :: IO () -> IO (FunPtr (IO ()))
    
    buttonSetCallback :: ButtonPtr -> FunPtr (IO ()) -> IO ()
    buttonSetCallback btn cb =
        withForeignPtr btn $ \p -> c_setClickCallback p cb
    
    buttonNew :: IO ButtonPtr
    buttonNew = ...
    

    Now Haskell data of type IO () can be wrapped in a FunPtr and passed into the GUI with buttonSetCallback. Whenever the button is pressed, the IO () action is performed.

    createButton :: IO ButtonPtr
    createButton = do
        btn <- buttonNew
        let buttonClicked = print "The button was clicked!"
        btnCallback <- makeClickCallback buttonClicked
        buttonSetCallback btn btnCallback
        return btn
    

    One thing to beware of with FunPtrs is that they aren’t garbage collected. You need to manually deallocate them when you’ve finished or you’ll have a memory leak. A good practice is to never share FunPtrs, and also never retain references to them on the Haskell side. That way your object can free the FunPtr as part of its cleanup. This requires yet another callback into Haskell (a freeFunPtr function) that should be shared between all your objects and is itself only freed when your executable terminates.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:

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.