* Haskell Foreign Function Interface 
** Example - Interface Linux/ C-library 

Description: It provides complete working examples about Haskell FFI
interfacing Linux GlibC (Linux C-Library).


 - File: [[file:libcScript.hs][file:libcScript.hs  ]]


Running: 

#+BEGIN_SRC sh 
$ stack ghci
Configuring GHCi with the following packages: 
GHCi, version 8.0.1: http://www.haskell.org/ghc/  :? for help
Wellcome to Haskell
it :: ()
Loaded GHCi configuration from /home/archbox/.ghci
Loaded GHCi configuration from /tmp/ghci32017/ghci-script
> 
> :script libcScript.hs 
cbrt :: Double -> Double
hypot :: Double -> Double -> Double
cputs :: CString -> IO ()
puts :: String -> IO ()
getpid :: IO Int
csystem :: CString -> IO Int
system :: String -> IO Int
c_gethostname :: Ptr CChar -> Int -> IO Int
gethostname :: IO String
testLibc :: IO ()



LibC FFI Tests
---------------------
Hello world São Paulo city
Hostname = ghostpc
Linux ghostpc 4.9.27-1-MANJARO #1 SMP PREEMPT Mon May 8 08:48:50 UTC 2017 x86_64 GNU/Linux
sh: wrong: command not found
cbrt 27.0       = 3.0000000000000004
hypot 80.0 60.0 = 100.0
it :: ()
> 

#+END_SRC
** Bookmarks
*** Haskell FFI - Documentation 

Haskell Documentation: 

 - [[https://hackage.haskell.org/package/base-4.9.1.0/docs/Foreign.html][Foreign]] - A collection of data types, classes, and functions for
   interfacing with another programming language.

 - [[https://hackage.haskell.org/package/base-4.9.1.0/docs/Foreign-C.html][Foreign.C]]        - Bundles the C specific FFI library functionality

 - [[https://hackage.haskell.org/package/base-4.9.1.0/docs/Foreign-C-Error.html][Foreign.C.Error]]

 - [[https://hackage.haskell.org/package/base-4.9.1.0/docs/Foreign-C-String.html][Foreign.C.String]] - Utilities for primitive marshalling of C strings.

 - [[https://hackage.haskell.org/package/base-4.9.1.0/docs/Foreign-C-Types.html][Foreign.C.Types]]  - Mapping of C types to corresponding Haskell types.

 - [[https://hackage.haskell.org/package/base-4.9.1.0/docs/Foreign-Marshal.html][Foreign.Marshal]] - Marshalling support

   - [[https://hackage.haskell.org/package/base-4.9.1.0/docs/Foreign-Marshal-Alloc.html][Foreign.Marshal.Alloc]] - The module Foreign.Marshal.Alloc provides
     operations to allocate and deallocate blocks of raw memory.

   - [[https://hackage.haskell.org/package/base-4.9.1.0/docs/Foreign-Marshal-Array.html][Foreign.Marshal.Array]] - Marshalling support: routines allocating,
     storing, and retrieving Haskell lists that are represented as
     arrays in the foreign language.

   - [[https://hackage.haskell.org/package/base-4.9.1.0/docs/Foreign-Marshal-Utils.html][Foreign.Marshal.Utils]]

 - [[https://hackage.haskell.org/package/base-4.9.1.0/docs/System-IO-Unsafe.html][System.IO.Unsafe]]

*** Haskell Wiki 

 - [[https://wiki.haskell.org/Category:FFI][Category:FFI - HaskellWiki]]

 - [[https://wiki.haskell.org/Cxx_foreign_function_interface][Cxx foreign function interface - HaskellWiki]]

 - [[https://wiki.haskell.org/FFI_complete_examples][FFI complete examples - HaskellWiki]]

 - [[https://wiki.haskell.org/CPlusPlus_from_Haskell][CPlusPlus from Haskell - HaskellWiki]]

 - [[https://wiki.haskell.org/FFI_cook_book][FFI cook book - HaskellWiki]]

*** Tutorials 

 - [[http://book.realworldhaskell.org/read/interfacing-with-c-the-ffi.html][Chapter 17. Interfacing with C: the FFI]]

 - [[https://en.wikibooks.org/wiki/Haskell/FFI][Haskell/FFI - Wikibooks, open books for an open world]]

 - 

 - 
