C # method of calling Haskell

Source: Internet
Author: User
Tags include

"System Environment"

Windows Server 2008 R2,haskell Platform 2013.2.0.0,GHC 7.6.3,cabal 1.16.0

"Action Steps"

1. Install Windows version Haskell Platform (does not support Windows Server), Haskell Platform integrates cabal (equivalent to. NET Msbuild+nuget), GHC (Glasgow Haskell Compiler,haskell compiler)

2. Write the Haskell code in the. hs file, add foreign export ccall in the code, and the sample code is as follows:

3. Write C code in the. c file with the following code:

#include <windows.h>
#include <Rts.h>
    
extern void __stginit_libpandoc (void);
    
BOOL stdcall DllMain (HANDLE hmodule, DWORD reason, void* reserved)
{
  static char* args[] = {"Libpandoc", Null};
  if (reason = = Dll_process_attach) {
    Startuphaskell (1, args, __stginit_libpandoc);
  }
  return TRUE;
}

4. Write cabal configuration files in. cabal files, such as:

Name:                   libpandoc
Version:                0.5
cabal-version:          >= 1.2
build-type:
Simple Executable Libpandoc.dll
  If os (Windows)
    cpp-options:        -dwin32
  Extensions:           Foreignfunctioninterface         
  hs-source-dirs:       src
  include-dirs:         src
  c-sources:            src/ PANDOC.C
  install-includes:     pandoc.h
  main-is:              libpandoc.hs
  ghc-options:          - No-hs-main-optl-shared-optl-s

5. Run the command Cabal build on the folder where the Haskell project is located, and then generate the header file when the compilation succeeds, such as Build\libpandoc.dll\libpandoc.dll-tmp\libpandoc_stub.h

#include "HsFFI.h"
#ifdef __cplusplus
extern "C" {
#endif
extern hsptr markdowntohtml (hsptr A1); c31/> #ifdef __cplusplus
}
#endif

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.