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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:08:24+00:00 2026-05-23T19:08:24+00:00

I’m building an interpreter for a dynamic programming language in Haskell. I’d like to

  • 0

I’m building an interpreter for a dynamic programming language in Haskell. I’d like to add a simple mechanism to call C functions. In the past, I’ve used the Haskell FFI to call C functions that I had explicitly declared the name and type of; this approach won’t work here because the interpreter won’t know the name or type of the C functions to be called until runtime.

Is it possible to declare and call C functions at runtime? Where should I begin?

  • 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-23T19:08:25+00:00Added an answer on May 23, 2026 at 7:08 pm

    Dynamic Importing

    If you can list all possible types for the C functions that may be called, then you can use the FFI’s dynamic import capability ( http://www.haskell.org/onlinereport/haskell2010/haskellch8.html). A dynamic import function wraps a C function at runtime. You’ll need to declare an import function for each C function type that you may be calling. (Actually, only the ABI matters, so you can treat all C pointer types as equivalent.)

    foreign import ccall "dynamic" mkPtrFun :: FunPtr (Ptr () -> IO (Ptr ())) -> Ptr () -> IO (Ptr ())
    

    If you have a pointer to a C function, you can make it callable from Haskell using this wrapper function.

    callWithNull :: FunPtr (Ptr a -> IO (Ptr ())) -> IO (Ptr ())
    callWithNull f = mkPtrFun f nullPtr
    

    If the types of the C functions are unknown when the Haskell code is compiled, then you cannot do this with the FFI.

    Dynamic Loading

    As for obtaining C function pointers dynamically, the FFI doesn’t help you. You can use dynamic loading libraries in C such as libdl. See the man pages: http://linux.die.net/man/3/dlopen .

    • 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’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build

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.