zhensydow/opencl — Issue #23: API (clBuildProgram) is not referentially transparent
Author: amcphail
Created: 2012-01-13 05:31:49+00:00
State: open

Your code from example01.hs has

-- Initialize Kernel
program <- clCreateProgramWithSource context programSource
clBuildProgram program [dev] ""
kernel <- clCreateKernel program "duparray"

Here `clBuildProgram` changes the `program` (from source to binary). This breaks referential transparency.

A more idiomatic approach would be to have `clBuildProgram` return the new `program`.

-- Initialize Kernel
program <- clCreateProgramWithSource context programSource
program' <- clBuildProgram program [dev] ""
kernel <- clCreateKernel program' "duparray"

This way you can also leverage the type system to prevent uncompiled programs being passed to `clCreateKernel`.