You have this line in your code, but that doesn&#39;t correlate to the imports you listed.<br><br>BS.replicate 64 &#39;\0&#39;<br><br>    import qualified Data.ByteString          as B  ( ByteString, packCStringLen, drop, length )<br>
    import qualified Data.ByteString.Internal as BI ( createAndTrim, createAndTrim&#39; )<br>    import qualified Data.ByteString.Unsafe   as BU ( unsafeUseAsCStringLen )<br><br>So you must have imported Data.ByteString.Lazy as BS somewhere.  Change that to B.replicate and it will probably work.<br>
<br><br><div class="gmail_quote">On Wed, Feb 27, 2013 at 11:41 AM, emacstheviking <span dir="ltr">&lt;<a href="mailto:objitsu@gmail.com" target="_blank">objitsu@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div><div><div><div>Karol, Alexander,<br><br></div>Thanks for your feedback... I am still a little confused as I shall explain... first of all let&#39;s look at the prototype for &#39;writeInterrupt&#39;,<div class="im">
<br>

<br>    writeInterrupt :: DeviceHandle -&gt; EndpointAddress -&gt; WriteAction<br><br></div></div>To me, that reads a &quot;takes a device handle and an endpoint address and returns a WriteAction&quot;, and to quote the WriteAction help text verbatim so there is no confusion:<br>


<br>    type WriteAction = ByteString -&gt; Timeout -&gt; IO (Size, Status)Source<br><br>    Handy type synonym for write transfers.<br><br>        &quot;A WriteAction is a function which takes a ByteString to write and a Timeout.<br>


         The function returns an IO action which, when exectued(sic), returns the number<br>         of bytes that were actually written paired with a Status flag which indicates whether<br>         the transfer Completed or TimedOut.&quot;<br>


<div><br><br></div><div>Now let&#39;s move to my original code and the &#39;right&#39; code...<br><br></div><div class="im"><div>    action &lt;- writeInterrupt handle endPoint<br></div></div><div class="im"><div>    let action = writeInterrupt handle endPoint<br>


<br></div></div><div><br>If I understand things correctly up to this point, my mistake was being too eager in using &quot;&lt;-&quot;, my mind at that point was obviously confusing the return value from WriteAction with the return type of writeInterrupt and I can see now that what I should have done was use &quot;let&quot; which captures the WriteAction that is returned which can be executed with the payload and the timeout on the next line:<br>


<br></div><div class="im"><div>    (size, status) &lt;- action payload 1000<br><br></div></div><div>On this line, the use of &quot;&lt;-&quot; is what is required in order to cause the promised IO action to  perform its duties and return me the tuple of data sent and status returned from the USB inner workings.<br>


<br></div><div>However, we now come to the new type checker error, and this one has me floored right now. Time and time again I find myself beating my head against a wall and tearing my hair out trying to understand the thousand-and-one variations on strings in Haskell! I even tried the &quot;string-conversions&quot; (convertString) package but decided to battle it out instead...<br>


<br></div><div>First the new code as edited in response to Karol:<div class="im"><br><br>    testBoard :: Device -&gt; DeviceHandle -&gt; IO ()<br></div>    testBoard dev handle = do<div class="im"><br>      putStrLn $ &quot;Inspecting device: \&quot;&quot; ++ (show dev) ++ &quot;\&quot;&quot;<br>
</div>

      -- write 0x00 0x00 0x00 0x00, get back same...we need to pad the                                      <br>      -- packet out to 64 bytes for a full-speed device... should probably                                  <br>


      -- get this (64) from the device configuration / description record                                   <br>      -- for maximum portability!                                                                           <br>


      let payload  = BS.replicate 64 &#39;\0&#39;<div class="im"><br>      let endPoint = EndpointAddress 0 Out<br></div><div class="im">      let action   = writeInterrupt handle endPoint<br>      (size, status) &lt;- action payload 1000<br>
      return ()<br>

<br></div>And the new error:<br></div><br>usb1.hs:64:28:<br>    Couldn&#39;t match expected type `bytestring-0.9.2.1:Data.ByteString.Internal.ByteString&#39;<br>                with actual type `ByteString&#39;<br>    In the first argument of `action&#39;, namely `payload&#39;<br>


    In a stmt of a &#39;do&#39; block: (size, status) &lt;- action payload 1000<div class="im"><br>    In the expression:<br>      do { putStrLn $ &quot;Inspecting device: \&quot;&quot; ++ (show dev) ++ &quot;\&quot;&quot;;<br>
</div>           let payload = BS.replicate 64 &#39;\NUL&#39;;<br>

           let endPoint = EndpointAddress 0 Out;<br>           let action = writeInterrupt handle endPoint;<br>           .... }<br><br><br></div>Where and why does it think that &quot;Data.ByteString.Internal.ByteString&quot; is the type of the first parameter to &quot;action&quot; which is quite clearly stated as being &quot;ByteString&quot; ???<br>


</div>I know that &quot;String&quot;, the native type is 4-bytes and that ByteString (Strict) and ByteString (Lazy) are both 8-bit, which is great, and I understand that the strict version (at least to me) feels like the rightmatch to be using for data buffers for a USB transfer but why oh why oh why can&#39;t I understand why the type checker picked up &quot;internal&quot; somewhere along the way?<br>


<br></div>In the source code for WriteAction we have this:<br><br><div><div><div>    type WriteAction = B.ByteString → Timeout → IO (Size, Status)<br><br></div><div>and at the top of the that source file:<br><br>    -- from bytestring:<br>


    import qualified Data.ByteString          as B  ( ByteString, packCStringLen, drop, length )<br>    import qualified Data.ByteString.Internal as BI ( createAndTrim, createAndTrim&#39; )<br>    import qualified Data.ByteString.Unsafe   as BU ( unsafeUseAsCStringLen )<br>


<br><br></div><div>So why is it trying to be &quot;internal&quot;! I have tried not to be lazy, I have read everything and looked everywhere before posting again. If it had said:<br><br>    type WriteAction = BI.ByteString → Timeout → IO (Size, Status)<br>


<br>I would have understood but it doesn&#39;t does it ?!<br>Can somebody explain for me so I can just get on and write my killer USB application please! LOL<br><br>:)<br></div><div>Thanks,<br>Sean.<br><br></div><div><br>


</div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div class="im">On 27 February 2013 12:07, Karol Samborski <span dir="ltr">&lt;<a href="mailto:edv.karol@gmail.com" target="_blank">edv.karol@gmail.com</a>&gt;</span> wrote:<br>


</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">Hi Sean,<br>
<br>
I think that your function for testing board should look like this:<br>
<br>
testBoard :: Device -&gt; DeviceHandle -&gt; IO ()<br>
testBoard dev handle = do<br>
  putStrLn $ &quot;Inspecting device: \&quot;&quot; ++ (show dev) ++ &quot;\&quot;\n&quot;<br>
  -- write 0x00 0x00 0x00 0x00, get back same...<br></div><div class="im">
  let payload  = pack &quot;\x00\x00\x00\x00&quot;<br>
  let endPoint = EndpointAddress 0 Out<br></div><div class="im">
  let action = writeInterrupt handle endPoint<br>
  (size, status) &lt;- action payload 1000<br>
  return ()<br>
<br>
You need to use let because writeInterrupt returns (Timeout -&gt;<br>
ByteString -&gt; IO (Size, Bool)) instead of IO (Timeout -&gt; ByteString -&gt;<br>
IO (Size, Bool))<br>
<br>
Karol<br>
<br></div><div class="im">
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</div></blockquote></div><br></div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br>