[Haskell-cafe] LLVM, getElementPtr?

Lally Singh lally.singh at gmail.com
Sun Dec 5 19:15:45 CET 2010

Hey all, I'm trying to get started generating LLVM code, but I'm
getting a rather cryptic error.

I wanted to create a function that takes a string and generates a
function calling to "puts" with that string as an argument:

buildReaderFun :: String -> CodeGenModule (Function (IO ()))
buildReaderFun nm = do
  puts <- newNamedFunction ExternalLinkage "puts" :: TFunction (Ptr
Word8 -> IO Word32)
  greetz <- createStringNul nm
  func <- createFunction ExternalLinkage $ do
    tmp <- getElementPtr0 greetz (0 :: Word32, ())
    call puts  tmp -- Throw away return value.
    ret ()
  return func

(based off of some code at this blog post:

But, I get this error:

    Ambiguous type variable `n' in the constraint:
      `Data.TypeLevel.Num.Sets.NatI n'
        arising from a use of `getElementPtr0'
                     at /research/phd/libmet/Listener.hs:16:11-49
    Probable fix: add a type signature that fixes these type variable(s)

My attempts at figuring out what type-level has to do with this, and
how to satisfy it have so far proven unsuccessful.

Can anyone shed a little light on what's going on?  Or pointers to
some documentation on any of this?


More information about the Haskell-Cafe mailing list