title: How to write a pure String to String function in Haskell FFI to C++
body: <p>I want to implement a function in C++ via Haskell FFI, which should have the (final) type of  <code>String -&gt; String</code>. Say, is it possible to <strong><em>re-implement</em></strong> the following function in C++ with the exact same signature?</p>
  
  <pre><code>import Data.Char
  toUppers:: String -&gt; String
  toUppers s = map toUpper s
  </code></pre>
  
  <p>In particular, I wanted to avoid having an IO in the return type because introducing the impurity (by that I mean the IO monad) for this simple task is logically unnecessary. All examples involing a C string I have seen so far involve returning an IO something or Ptr which cannot be converted back to a pure <code>String</code>.</p>
  
  <p>The reason I want to do this is that I have the impression that marshaling is messy with FFI. Maybe if I can fix the simplest case above (other than primitive types such as int), then I can do whatever data parsing I want on the C++ side, which should be easy.</p>
  
  <p>The cost of parsing is negligible compared to the computation that I want to do between the marshalling to/from strings.</p>
  
  <p>Thanks in advance.</p>