Looking at the source, we have iadd :: (IsInteger c, ABinOp ab (vc)) => a -> b -> CodeGenFunction r (vc) . Then the first two iadd arguments should be members of typeclass ABinOp , but you already knew that, GHC said.
I think (v0 c0) not a problem, I suspect. Considering the source, ABinOp is defined as class ABinOp abc | ab -> c where class ABinOp abc | ab -> c where . The argument of the last type c automatically determined by the type checking method taking into account any two input arguments (their types will be inferred from the types of arguments that you pass to the functions using the ABinOp constraint). This is due to the functional dependency in the class declaration. I also suspect that the second error is directly related to the first.
Now to the problem. GHC claims that the instance does not exist, where the first two type arguments for ABinOp are Int32 ; in fact, from what I see looking at the source, the GHC is absolutely right. The only ABinOp instances I see are:
instance ABinOp (Value a) (Value a) (Value a) where abinop _ op (Value a1) (Value a2) = buildBinOp op a1 a2 instance ABinOp (ConstValue a) (Value a) (Value a) where abinop _ op (ConstValue a1) (Value a2) = buildBinOp op a1 a2 instance ABinOp (Value a) (ConstValue a) (Value a) where abinop _ op (Value a1) (ConstValue a2) = buildBinOp op a1 a2 instance ABinOp (ConstValue a) (ConstValue a) (ConstValue a) where abinop cop _ (ConstValue a1) (ConstValue a2) = return $ ConstValue $ cop a1 a2 instance (IsConst a) => ABinOp (Value a) a (Value a) where abinop cop op a1 a2 = abinop cop op a1 (constOf a2) instance (IsConst a) => ABinOp a (Value a) (Value a) where abinop cop op a1 a2 = abinop cop op (constOf a1) a2
Naturally, your use of iadd must match one of them (unless it is hidden somewhere else). As you can see, Int32 not included in any of them. Well, let's take a look at Value and ConstValue .
newtype Value a = Value { unValue :: FFI.ValueRef } deriving (Show, Typeable) newtype ConstValue a = ConstValue { unConstValue :: FFI.ValueRef } deriving (Show, Typeable)
Groping deeper into FFI (an alias for LLVM.FFI.Core ), we find:
data Value deriving (Typeable) type ValueRef = Ptr Value
Now we can assume that iadd requires statements like Value Ptr or ConstValue Ptr . The difference between them is unknown to me.
Now, personally, I know very little about Ptr in Haskell. edit: In light of this fact, I cannot say how to create an instance of Ptr , but the answer below does me. All of the above is still in progress.