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

  • Home
  • SEARCH
  • 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 8063893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:11:39+00:00 2026-06-05T11:11:39+00:00

Having a rather low level application, I came into a sitatuion where I needed

  • 0

Having a rather low level application, I came into a sitatuion where I needed to determine the address of a Haskell function. I was able to do that with FFI, that is C, but I would like to do it directly in Haskell.

Here is my current solution with FFI:

main.hs:

{-# LANGUAGE ForeignFunctionInterface #-}
module Main where

import Foreign
import Foreign.C.Types
import Text.Printf

foreign import ccall "getFuncAddr"
  getFuncAddr :: CULong

main :: IO ()
main = do
  printf "0x%016x\n" (fromIntegral getFuncAddr :: Word64)

foreign export ccall func :: IO ()
func :: IO ()
func = do
  printf "hello world\n"

ffi.c:

void func(void);

unsigned long getFuncAddr(void)
{
    return (unsigned long) func;
}

Makefile:

all: main
    ./$<
    objdump -D $< | grep '<func>'

main: main.hs ffi.c
    ghc --make -O2 $^ -o $@

as always, also available as a gist.

  • 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-05T11:11:41+00:00Added an answer on June 5, 2026 at 11:11 am

    Try this:

    {-# LANGUAGE ForeignFunctionInterface #-}
    module Main where
    
    import Foreign
    import Foreign.C.Types
    import Text.Printf
    
    foreign import ccall "&func"
      funcaddr :: FunPtr (IO ())
    
    main :: IO ()
    main = do
      printf "0x%016x\n" (fromIntegral (ptrToIntPtr (castFunPtrToPtr funcaddr)) :: Int)
    
    foreign export ccall func :: IO ()
    func :: IO ()
    func = do
      printf "hello world\n"
    

    See this section of the Haskell 2010 report, and look for “Static Addresses.”

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

Sidebar

Related Questions

I'm having a rather strange issue with Entity Framework 4.3 in my MVC application.
I am having a heck of time with something that seems rather straightforward but
I am having the following problem. I am now using the low-level google datastore
I am having a rather frustrating issue trying to call a web service that
I'm having a rather heated debate into IE's XHTML Compatibility. The only thing is,
I'm having a problem with an android application that I'm working on. My application
Im having rather an annoying problem. I have a class called Person and a
I've been having this rather frustrating problem, and having failed so many times, I'm
I'm having a rather odd issue where the menu for an activity works totally
I'm rather new to normalizing tables and I'm having some troubles wrapping my head

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.