Skip to content

Instantly share code, notes, and snippets.

@sdiehl
Last active February 24, 2020 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdiehl/0491596cd7faaf95503e4b7066cffe62 to your computer and use it in GitHub Desktop.
Save sdiehl/0491596cd7faaf95503e4b7066cffe62 to your computer and use it in GitHub Desktop.
cabal-version: 3.0
name: example
build-type: Simple
version: 1.0.0
executable example
main-is: Main.hs
build-depends: base, ghc-prim
default-language: Haskell2010
ghc-options: -ddump-cmm
c-sources: example.cmm
#include "Cmm.h"
example (W_ n) {
entry:
return (n+1);
}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE GHCForeignImportPrim #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnliftedFFITypes #-}
module Main where
import GHC.Prim
import GHC.Word
foreign import prim "example" example_cmm :: Word# -> Word#
example :: Word64 -> Word64
example (W64# n) = W64# (example_cmm n)
main :: IO ()
main = print (example 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment