@@ -257,14 +257,16 @@ execApp' env ctxt (EP _ (UN "mkForeign") _) (_:fn:(EHandle h):rest)
257257 execApp' env ctxt ioUnit rest
258258
259259execApp' env ctxt (EP _ (UN "mkForeign") _) (_:fn:(EPtr p):rest)
260− | Just (FFun "isNull" _ _) <- foreignFromTT fn = let res = if p == nullPtr then 1 else 0 in
261− execApp' env ctxt (EConstant (I res)) rest
260+ | Just (FFun "isNull" _ _) <- foreignFromTT fn = let res = ioWrap . EConstant . I $
261+ if p == nullPtr then 1 else 0
262+ in execApp' env ctxt res rest
262263
263−execApp' env ctxt f@(EP _ (UN "mkForeign") _) args@(ty:fn:xs) | Just (FFun _ argTs retT) <- foreignFromTT fn
264+execApp' env ctxt f@(EP _ (UN "mkForeign") _) args@(ty:fn:xs) | Just (FFun f argTs retT) <- foreignFromTT fn
264265 , length xs >= length argTs =
265266 do res <- stepForeign (ty:fn:take (length argTs) xs)
266267 case res of
267− Nothing -> fail "Could not call foreign function"
268+ Nothing -> fail $ "Could not call foreign function \"" ++ f ++
269+ "\" with args " ++ show (take (length argTs) xs)
268270 Just r -> return (mkEApp r (drop (length argTs) xs))
269271 | otherwise = return (mkEApp f args)
270272