No subject
Thu Jan 10 18:17:16 CET 2013
h-actual-type-error-when-using-codec-bmp
and
when I actually listed the bytestring packages as suggested I get this
(terrible!) output:
WARNING: there are broken packages. Run 'ghc-pkg check' for more
details.
/var/lib/ghc/package.conf.d
bytestring-0.9.2.1
/home/sean/.ghc/i386-linux-7.4.2/package.conf.d
bytestring-0.10.0.1
and doing the suggested "ghc-pkg check" made me reach for the toilet
rolls....
WARNING: there are broken packages. Run 'ghc-pkg check' for more details.
/var/lib/ghc/package.conf.d
bytestring-0.9.2.1
/home/sean/.ghc/i386-linux-7.4.2/package.conf.d
bytestring-0.10.0.1
sean at sean-Dimension-4700 ~/Documents/haskell/usb $ ghc-pkg check
There are problems in package snap-core-0.9.3.1:
dependency "vector-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't
exist
There are problems in package tls-extra-0.6.1:
dependency "vector-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't
exist
There are problems in package crypto-numbers-0.1.3:
dependency "vector-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't
exist
There are problems in package repa-io-3.2.2.201204.1:
dependency "vector-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't
exist
There are problems in package repa-algorithms-3.2.2.201204.1:
dependency "vector-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't
exist
There are problems in package repa-3.2.2.201204.1:
dependency "vector-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't
exist
There are problems in package vty-4.7.0.20:
dependency "vector-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't
exist
There are problems in package pango-0.12.2:
dependency "cairo-0.12.3-89ddba0b76b80ddab58fabdf2a845c76" doesn't exist
There are problems in package webkit-0.12.3:
dependency "cairo-0.12.3-89ddba0b76b80ddab58fabdf2a845c76" doesn't exist
There are problems in package gtk-0.12.3:
dependency "cairo-0.12.3-89ddba0b76b80ddab58fabdf2a845c76" doesn't exist
The following packages are broken, either because they have a problem
listed above, or because they depend on a broken package.
snap-core-0.9.3.1
tls-extra-0.6.1
crypto-numbers-0.1.3
repa-io-3.2.2.201204.1
repa-algorithms-3.2.2.201204.1
repa-3.2.2.201204.1
vty-4.7.0.20
pango-0.12.2
webkit-0.12.3
gtk-0.12.3
hakyll-4.1.4.0
snap-server-0.9.3.1
http-conduit-1.8.7.1
tls-1.1.2
crypto-pubkey-0.1.2
gloss-raster-1.7.7.201204.1
yi-0.6.6.0
hbro-0.9.0.0
hbro-contrib-0.9.0.0
ltk-0.12.0.0
So... I think that my real problem is that I have a badly broken package
setup. I am going to remove both bytestring packages as well as all those
broken things (I don't need them anyway( and reinstall and see what
happens. I hope it just goes away.... I really want to be USB programming
not fixing up my installation.. nothing like computers to make life awkward=
.
Thanks.
Sean.
On 27 February 2013 19:21, David McBride <toad3k at gmail.com> wrote:
> You have this line in your code, but that doesn't correlate to the import=
s
> you listed.
>
> BS.replicate 64 '\0'
>
> import qualified Data.ByteString as B ( ByteString,
> packCStringLen, drop, length )
> import qualified Data.ByteString.Internal as BI ( createAndTrim,
> createAndTrim' )
> import qualified Data.ByteString.Unsafe as BU (
> unsafeUseAsCStringLen )
>
> So you must have imported Data.ByteString.Lazy as BS somewhere. Change
> that to B.replicate and it will probably work.
>
>
> On Wed, Feb 27, 2013 at 11:41 AM, emacstheviking <objitsu at gmail.com>wrote=
:
>
>> Karol, Alexander,
>>
>> Thanks for your feedback... I am still a little confused as I shall
>> explain... first of all let's look at the prototype for 'writeInterrupt'=
,
>>
>>
>> writeInterrupt :: DeviceHandle -> EndpointAddress -> WriteAction
>>
>> To me, that reads a "takes a device handle and an endpoint address and
>> returns a WriteAction", and to quote the WriteAction help text verbatim =
so
>> there is no confusion:
>>
>> type WriteAction =3D ByteString -> Timeout -> IO (Size, Status)Sourc=
e
>>
>> Handy type synonym for write transfers.
>>
>> "A WriteAction is a function which takes a ByteString to write
>> and a Timeout.
>> The function returns an IO action which, when exectued(sic),
>> returns the number
>> of bytes that were actually written paired with a Status flag
>> which indicates whether
>> the transfer Completed or TimedOut."
>>
>>
>> Now let's move to my original code and the 'right' code...
>>
>> action <- writeInterrupt handle endPoint
>> let action =3D writeInterrupt handle endPoint
>>
>>
>> If I understand things correctly up to this point, my mistake was being
>> too eager in using "<-", my mind at that point was obviously confusing t=
he
>> return value from WriteAction with the return type of writeInterrupt and=
I
>> can see now that what I should have done was use "let" which captures th=
e
>> WriteAction that is returned which can be executed with the payload and =
the
>> timeout on the next line:
>>
>> (size, status) <- action payload 1000
>>
>> On this line, the use of "<-" is what is required in order to cause the
>> promised IO action to perform its duties and return me the tuple of dat=
a
>> sent and status returned from the USB inner workings.
>>
>> 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
>> "string-conversions" (convertString) package but decided to battle it ou=
t
>> instead...
>>
>> First the new code as edited in response to Karol:
>>
>>
>> testBoard :: Device -> DeviceHandle -> IO ()
>> testBoard dev handle =3D do
>>
>> putStrLn $ "Inspecting device: \"" ++ (show dev) ++ "\""
>> -- write 0x00 0x00 0x00 0x00, get back same...we need to pad
>> the
>> -- packet out to 64 bytes for a full-speed device... should
>> probably
>> -- get this (64) from the device configuration / description
>> record
>> -- for maximum
>> portability!
>>
>> let payload =3D BS.replicate 64 '\0'
>>
>> let endPoint =3D EndpointAddress 0 Out
>> let action =3D writeInterrupt handle endPoint
>> (size, status) <- action payload 1000
>> return ()
>>
>> And the new error:
>>
>> usb1.hs:64:28:
>> Couldn't match expected type
>> `bytestring-0.9.2.1:Data.ByteString.Internal.ByteString'
>> with actual type `ByteString'
>> In the first argument of `action', namely `payload'
>> In a stmt of a 'do' block: (size, status) <- action payload 1000
>>
>> In the expression:
>> do { putStrLn $ "Inspecting device: \"" ++ (show dev) ++ "\"";
>> let payload =3D BS.replicate 64 '\NUL';
>> let endPoint =3D EndpointAddress 0 Out;
>> let action =3D writeInterrupt handle endPoint;
>> .... }
>>
>>
>> Where and why does it think that "Data.ByteString.Internal.ByteString" i=
s
>> the type of the first parameter to "action" which is quite clearly state=
d
>> as being "ByteString" ???
>> I know that "String", 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 wh=
y
>> oh why can't I understand why the type checker picked up "internal"
>> somewhere along the way?
>>
>> In the source code for WriteAction we have this:
>>
>> type WriteAction =3D B.ByteString =E2=86=92 Timeout =E2=86=92 IO (Si=
ze, Status)
>>
>> and at the top of the that source file:
>>
>> -- from bytestring:
>> import qualified Data.ByteString as B ( ByteString,
>> packCStringLen, drop, length )
>> import qualified Data.ByteString.Internal as BI ( createAndTrim,
>> createAndTrim' )
>> import qualified Data.ByteString.Unsafe as BU (
>> unsafeUseAsCStringLen )
>>
>>
>> So why is it trying to be "internal"! I have tried not to be lazy, I hav=
e
>> read everything and looked everywhere before posting again. If it had sa=
id:
>>
>> type WriteAction =3D BI.ByteString =E2=86=92 Timeout =E2=86=92 IO (S=
ize, Status)
>>
>> I would have understood but it doesn't does it ?!
>> Can somebody explain for me so I can just get on and write my killer USB
>> application please! LOL
>>
>> :)
>> Thanks,
>> Sean.
>>
>>
>>
>>
>>
>> On 27 February 2013 12:07, Karol Samborski <edv.karol at gmail.com> wrote:
>>
>>> Hi Sean,
>>>
>>> I think that your function for testing board should look like this:
>>>
>>> testBoard :: Device -> DeviceHandle -> IO ()
>>> testBoard dev handle =3D do
>>> putStrLn $ "Inspecting device: \"" ++ (show dev) ++ "\"\n"
>>> -- write 0x00 0x00 0x00 0x00, get back same...
>>> let payload =3D pack "\x00\x00\x00\x00"
>>> let endPoint =3D EndpointAddress 0 Out
>>> let action =3D writeInterrupt handle endPoint
>>> (size, status) <- action payload 1000
>>> return ()
>>>
>>> You need to use let because writeInterrupt returns (Timeout ->
>>> ByteString -> IO (Size, Bool)) instead of IO (Timeout -> ByteString ->
>>> IO (Size, Bool))
>>>
>>> Karol
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
--047d7bf0c332b87e7304d6bac33a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">David, =C2=A0maybe my code got chopped then because this i=
s the start of my program:<div><br><font face=3D"courier new, monospace">=
=C2=A0 =C2=A0 module Main where<br>=C2=A0 =C2=A0 import Data.ByteString.Cha=
r8 as BS hiding (putStrLn) =C2=A0 ***HERE IT IS***<br>
=C2=A0 =C2=A0 import Data.String.Conversions as SC<br>=C2=A0 =C2=A0 import =
Data.Word (Word16)<br>=C2=A0 =C2=A0 import Data.Vector as V (filterM, null,=
(!)) --as V hiding ((++)) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<br>=C2=A0 =C2=A0 import System.USB<br>=
=C2=A0 =C2=A0 import System.Environment</font><div style>
<div><font face=3D"courier new, monospace"><br></font></div><div style>wher=
e the "BS" (pardon the pun) is quite plainly defined. And changin=
g it as suggested only yields this:</div><div style><br></div><div style>
<font face=3D"courier new, monospace">usb1.hs:61:18:<br>=C2=A0 =C2=A0 Not i=
n scope: `B.replicate'<br>=C2=A0 =C2=A0 Perhaps you meant `BS.replicate=
' (imported from Data.ByteString.Char8)</font><div><br></div><div style=
>So I don't think that's the solution.</div>
<div style>From digging around it seems that I might have in fact got a bro=
ken set of libraries. I found this:=C2=A0<a href=3D"http://stackoverflow.co=
m/questions/12576817/couldnt-match-expected-type-with-actual-type-error-whe=
n-using-codec-bmp">http://stackoverflow.com/questions/12576817/couldnt-matc=
h-expected-type-with-actual-type-error-when-using-codec-bmp</a>=C2=A0and wh=
en I actually listed the bytestring packages as suggested I get this (terri=
ble!) output:</div>
<div style><br></div><font face=3D"trebuchet ms, sans-serif">=C2=A0 =C2=A0 =
WARNING: there are broken packages. =C2=A0Run 'ghc-pkg check' for m=
ore details.<br>=C2=A0 =C2=A0 /var/lib/ghc/package.conf.d<br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0bytestring-0.9.2.1<br>=C2=A0 =C2=A0 /home/sean/.ghc/i386-linux=
-7.4.2/package.conf.d<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0bytestring-0.10.0.1</font></div><div style><br><=
/div><div style><div style>and doing the suggested "ghc-pkg check"=
; made me reach for the toilet rolls....</div><div style><br></div><div sty=
le><div><font face=3D"trebuchet ms, sans-serif">WARNING: there are broken p=
ackages. =C2=A0Run 'ghc-pkg check' for more details.</font></div>
<div><font face=3D"trebuchet ms, sans-serif">/var/lib/ghc/package.conf.d</f=
ont></div><div><font face=3D"trebuchet ms, sans-serif">=C2=A0 =C2=A0bytestr=
ing-0.9.2.1</font></div><div><font face=3D"trebuchet ms, sans-serif">/home/=
sean/.ghc/i386-linux-7.4.2/package.conf.d</font></div>
<div><font face=3D"trebuchet ms, sans-serif">=C2=A0 =C2=A0bytestring-0.10.0=
.1</font></div><div><font face=3D"trebuchet ms, sans-serif">sean at sean-Dimen=
sion-4700 ~/Documents/haskell/usb $ ghc-pkg check</font></div><div><font fa=
ce=3D"trebuchet ms, sans-serif">There are problems in package snap-core-0.9=
.3.1:</font></div>
<div><font face=3D"trebuchet ms, sans-serif">=C2=A0 dependency "vector=
-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't exist</font></=
div><div><font face=3D"trebuchet ms, sans-serif">There are problems in pack=
age tls-extra-0.6.1:</font></div>
<div><font face=3D"trebuchet ms, sans-serif">=C2=A0 dependency "vector=
-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't exist</font></=
div><div><font face=3D"trebuchet ms, sans-serif">There are problems in pack=
age crypto-numbers-0.1.3:</font></div>
<div><font face=3D"trebuchet ms, sans-serif">=C2=A0 dependency "vector=
-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't exist</font></=
div><div><font face=3D"trebuchet ms, sans-serif">There are problems in pack=
age repa-io-3.2.2.201204.1:</font></div>
<div><font face=3D"trebuchet ms, sans-serif">=C2=A0 dependency "vector=
-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't exist</font></=
div><div><font face=3D"trebuchet ms, sans-serif">There are problems in pack=
age repa-algorithms-3.2.2.201204.1:</font></div>
<div><font face=3D"trebuchet ms, sans-serif">=C2=A0 dependency "vector=
-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't exist</font></=
div><div><font face=3D"trebuchet ms, sans-serif">There are problems in pack=
age repa-3.2.2.201204.1:</font></div>
<div><font face=3D"trebuchet ms, sans-serif">=C2=A0 dependency "vector=
-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't exist</font></=
div><div><font face=3D"trebuchet ms, sans-serif">There are problems in pack=
age vty-4.7.0.20:</font></div>
<div><font face=3D"trebuchet ms, sans-serif">=C2=A0 dependency "vector=
-0.10.0.1-fdf8e0c3f3c1cae1113ab97c34aa5c14" doesn't exist</font></=
div><div><font face=3D"trebuchet ms, sans-serif">There are problems in pack=
age pango-0.12.2:</font></div>
<div><font face=3D"trebuchet ms, sans-serif">=C2=A0 dependency "cairo-=
0.12.3-89ddba0b76b80ddab58fabdf2a845c76" doesn't exist</font></div=
><div><font face=3D"trebuchet ms, sans-serif">There are problems in package=
webkit-0.12.3:</font></div>
<div><font face=3D"trebuchet ms, sans-serif">=C2=A0 dependency "cairo-=
0.12.3-89ddba0b76b80ddab58fabdf2a845c76" doesn't exist</font></div=
><div><font face=3D"trebuchet ms, sans-serif">There are problems in package=
gtk-0.12.3:</font></div>
<div><font face=3D"trebuchet ms, sans-serif">=C2=A0 dependency "cairo-=
0.12.3-89ddba0b76b80ddab58fabdf2a845c76" doesn't exist</font></div=
><div><font face=3D"trebuchet ms, sans-serif"><br></font></div><div><font f=
ace=3D"trebuchet ms, sans-serif">The following packages are broken, either =
because they have a problem</font></div>
<div><font face=3D"trebuchet ms, sans-serif">listed above, or because they =
depend on a broken package.</font></div><div><font face=3D"trebuchet ms, sa=
ns-serif">snap-core-0.9.3.1</font></div><div><font face=3D"trebuchet ms, sa=
ns-serif">tls-extra-0.6.1</font></div>
<div><font face=3D"trebuchet ms, sans-serif">crypto-numbers-0.1.3</font></d=
iv><div><font face=3D"trebuchet ms, sans-serif">repa-io-3.2.2.201204.1</fon=
t></div><div><font face=3D"trebuchet ms, sans-serif">repa-algorithms-3.2.2.=
201204.1</font></div>
<div><font face=3D"trebuchet ms, sans-serif">repa-3.2.2.201204.1</font></di=
v><div><font face=3D"trebuchet ms, sans-serif">vty-4.7.0.20</font></div><di=
v><font face=3D"trebuchet ms, sans-serif">pango-0.12.2</font></div><div><fo=
nt face=3D"trebuchet ms, sans-serif">webkit-0.12.3</font></div>
<div><font face=3D"trebuchet ms, sans-serif">gtk-0.12.3</font></div><div><f=
ont face=3D"trebuchet ms, sans-serif">hakyll-4.1.4.0</font></div><div><font=
face=3D"trebuchet ms, sans-serif">snap-server-0.9.3.1</font></div><div><fo=
nt face=3D"trebuchet ms, sans-serif">http-conduit-1.8.7.1</font></div>
<div><font face=3D"trebuchet ms, sans-serif">tls-1.1.2</font></div><div><fo=
nt face=3D"trebuchet ms, sans-serif">crypto-pubkey-0.1.2</font></div><div><=
font face=3D"trebuchet ms, sans-serif">gloss-raster-1.7.7.201204.1</font></=
div>
<div><font face=3D"trebuchet ms, sans-serif">yi-0.6.6.0</font></div><div><f=
ont face=3D"trebuchet ms, sans-serif">hbro-0.9.0.0</font></div><div><font f=
ace=3D"trebuchet ms, sans-serif">hbro-contrib-0.9.0.0</font></div><div><fon=
t face=3D"trebuchet ms, sans-serif">ltk-0.12.0.0</font></div>
<div><br></div><div><br></div><div style>So... I think that my real problem=
is that I have a badly broken package setup. I am going to remove both byt=
estring packages as well as all those broken things (I don't need them =
anyway( and reinstall and see what happens. I hope it just goes away.... I =
really want to be USB programming not fixing up my installation.. nothing l=
ike computers to make life awkward.</div>
<div style><br></div><div style>Thanks.</div><div style>Sean.</div><div sty=
le><br></div><div style><br></div><div style><br></div></div></div></div></=
div></div><div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">On =
27 February 2013 19:21, David McBride <span dir=3D"ltr"><<a href=3D"mail=
to:toad3k at gmail.com" target=3D"_blank">toad3k at gmail.com</a>></span> wrot=
e:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">You have this line in your code, but that do=
esn't correlate to the imports you listed.<br><br>BS.replicate 64 '=
\0'<br>
<br>=C2=A0=C2=A0=C2=A0 import qualified Data.ByteString=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 as B=C2=A0 ( ByteString, packCStringLe=
n, drop, length )<br>
=C2=A0=C2=A0=C2=A0 import qualified Data.ByteString.Internal as BI ( create=
AndTrim, createAndTrim' )<br>=C2=A0=C2=A0=C2=A0 import qualified Data.B=
yteString.Unsafe=C2=A0=C2=A0 as BU ( unsafeUseAsCStringLen )<br><br>So you =
must have imported Data.ByteString.Lazy as BS somewhere.=C2=A0 Change that =
to B.replicate and it will probably work.<br>
<br><br><div class=3D"gmail_quote">On Wed, Feb 27, 2013 at 11:41 AM, emacst=
heviking <span dir=3D"ltr"><<a href=3D"mailto:objitsu at gmail.com" target=
=3D"_blank">objitsu at gmail.com</a>></span> wrote:<br><blockquote class=3D=
"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding=
-left:1ex">
<div dir=3D"ltr"><div><div><div><div><div>Karol, Alexander,<br><br></div>Th=
anks for your feedback... I am still a little confused as I shall explain..=
. first of all let's look at the prototype for 'writeInterrupt'=
,<div>
<br>
<br>=C2=A0=C2=A0=C2=A0 writeInterrupt :: DeviceHandle -> EndpointAddress=
-> WriteAction<br><br></div></div>To me, that reads a "takes a dev=
ice handle and an endpoint address and returns a WriteAction", and to =
quote the WriteAction help text verbatim so there is no confusion:<br>
<br>=C2=A0=C2=A0=C2=A0 type WriteAction =3D ByteString -> Timeout -> =
IO (Size, Status)Source<br><br>=C2=A0=C2=A0=C2=A0 Handy type synonym for wr=
ite transfers.<br><br>=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "A WriteAc=
tion is a function which takes a ByteString to write and a Timeout.<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 The function returns an IO=
action which, when exectued(sic), returns the number<br>=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 of bytes that were actually written paired w=
ith a Status flag which indicates whether<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 the transfer Completed or TimedOut."<br>
<div><br><br></div><div>Now let's move to my original code and the '=
;right' code...<br><br></div><div><div>=C2=A0=C2=A0=C2=A0 action <- =
writeInterrupt handle endPoint<br></div></div><div><div>=C2=A0=C2=A0=C2=A0 =
let action =3D 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 "<-", my mind at that=
point was obviously confusing the return value from WriteAction with the r=
eturn type of writeInterrupt and I can see now that what I should have done=
was use "let" which captures the WriteAction that is returned wh=
ich can be executed with the payload and the timeout on the next line:<br>
<br></div><div><div>=C2=A0=C2=A0=C2=A0 (size, status) <- action payload =
1000<br><br></div></div><div>On this line, the use of "<-" is =
what is required in order to cause the promised IO action to=C2=A0 perform =
its duties and return me the tuple of data sent and status returned from th=
e 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 thous=
and-and-one variations on strings in Haskell! I even tried the "string=
-conversions" (convertString) package but decided to battle it out ins=
tead...<br>
<br></div><div>First the new code as edited in response to Karol:<div><br><=
br>=C2=A0=C2=A0=C2=A0 testBoard :: Device -> DeviceHandle -> IO ()<br=
></div>=C2=A0=C2=A0=C2=A0 testBoard dev handle =3D do<div><br>=C2=A0=C2=A0=
=C2=A0 =C2=A0 putStrLn $ "Inspecting device: \"" ++ (show de=
v) ++ "\""<br>
</div>
=C2=A0=C2=A0=C2=A0 =C2=A0 -- write 0x00 0x00 0x00 0x00, get back same...we =
need to pad the=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 =C2=A0 -- packet out to 64 bytes for a =
full-speed device... should probably=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 <br>
=C2=A0=C2=A0=C2=A0 =C2=A0 -- get this (64) from the device configuration / =
description record=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <b=
r>=C2=A0=C2=A0=C2=A0 =C2=A0 -- for maximum portability!=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <br>
=C2=A0=C2=A0=C2=A0 =C2=A0 let payload=C2=A0 =3D BS.replicate 64 '\0'=
;<div><br>=C2=A0=C2=A0=C2=A0 =C2=A0 let endPoint =3D EndpointAddress 0 Out<=
br></div><div>=C2=A0=C2=A0=C2=A0 =C2=A0 let action=C2=A0=C2=A0 =3D writeInt=
errupt handle endPoint<br>=C2=A0=C2=A0=C2=A0 =C2=A0 (size, status) <- ac=
tion payload 1000<br>
=C2=A0=C2=A0=C2=A0 =C2=A0 return ()<br>
<br></div>And the new error:<br></div><br>usb1.hs:64:28:<br>=C2=A0=C2=A0=C2=
=A0 Couldn't match expected type `bytestring-0.9.2.1:Data.ByteString.In=
ternal.ByteString'<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 with actual type `ByteString'=
;<br>=C2=A0=C2=A0=C2=A0 In the first argument of `action', namely `payl=
oad'<br>
=C2=A0=C2=A0=C2=A0 In a stmt of a 'do' block: (size, status) <- =
action payload 1000<div><br>=C2=A0=C2=A0=C2=A0 In the expression:<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 do { putStrLn $ "Inspecting device: \"&q=
uot; ++ (show dev) ++ "\"";<br>
</div>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let payl=
oad =3D BS.replicate 64 '\NUL';<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let endPoint =
=3D EndpointAddress 0 Out;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 let action =3D writeInterrupt handle endPoint;<br>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .... }<br><br><br></div=
>Where and why does it think that "Data.ByteString.Internal.ByteString=
" is the type of the first parameter to "action" which is qu=
ite clearly stated as being "ByteString" ???<br>
</div>I know that "String", the native type is 4-bytes and that B=
yteString (Strict) and ByteString (Lazy) are both 8-bit, which is great, an=
d I understand that the strict version (at least to me) feels like the righ=
tmatch to be using for data buffers for a USB transfer but why oh why oh wh=
y can't I understand why the type checker picked up "internal"=
; somewhere along the way?<br>
<br></div>In the source code for WriteAction we have this:<br><br><div><div=
><div>=C2=A0=C2=A0=C2=A0 type WriteAction =3D B.ByteString =E2=86=92 Timeou=
t =E2=86=92 IO (Size, Status)<br><br></div><div>and at the top of the that =
source file:<br><br>=C2=A0=C2=A0=C2=A0 -- from bytestring:<br>
=C2=A0=C2=A0=C2=A0 import qualified Data.ByteString=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 as B=C2=A0 ( ByteString, packCStringLen, dro=
p, length )<br>=C2=A0=C2=A0=C2=A0 import qualified Data.ByteString.Internal=
as BI ( createAndTrim, createAndTrim' )<br>=C2=A0=C2=A0=C2=A0 import q=
ualified Data.ByteString.Unsafe=C2=A0=C2=A0 as BU ( unsafeUseAsCStringLen )=
<br>
<br><br></div><div>So why is it trying to be "internal"! I have t=
ried not to be lazy, I have read everything and looked everywhere before po=
sting again. If it had said:<br><br>=C2=A0=C2=A0=C2=A0 type WriteAction =3D=
BI.ByteString =E2=86=92 Timeout =E2=86=92 IO (Size, Status)<br>
<br>I would have understood but it doesn't does it ?!<br>Can somebody e=
xplain for me so I can just get on and write my killer USB application plea=
se! LOL<br><br>:)<br></div><div>Thanks,<br>Sean.<br><br></div><div><br>
</div><div><br></div></div></div><div class=3D"gmail_extra"><br><br><div cl=
ass=3D"gmail_quote"><div>On 27 February 2013 12:07, Karol Samborski <span d=
ir=3D"ltr"><<a href=3D"mailto:edv.karol at gmail.com" target=3D"_blank">edv=
.karol at gmail.com</a>></span> wrote:<br>
</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;b=
order-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Hi Sean,<br>
<br>
I think that your function for testing board should look like this:<br>
<br>
testBoard :: Device -> DeviceHandle -> IO ()<br>
testBoard dev handle =3D do<br>
=C2=A0 putStrLn $ "Inspecting device: \"" ++ (show dev) ++ &=
quot;\"\n"<br>
=C2=A0 -- write 0x00 0x00 0x00 0x00, get back same...<br></div><div>
=C2=A0 let payload =C2=A0=3D pack "\x00\x00\x00\x00"<br>
=C2=A0 let endPoint =3D EndpointAddress 0 Out<br></div><div>
=C2=A0 let action =3D writeInterrupt handle endPoint<br>
=C2=A0 (size, status) <- action payload 1000<br>
=C2=A0 return ()<br>
<br>
You need to use let because writeInterrupt returns (Timeout -><br>
ByteString -> IO (Size, Bool)) instead of IO (Timeout -> ByteString -=
><br>
IO (Size, Bool))<br>
<br>
Karol<br>
<br></div><div>
_______________________________________________<br>
Beginners mailing list<br>
<a href=3D"mailto:Beginners at haskell.org" target=3D"_blank">Beginners at haskel=
l.org</a><br>
<a href=3D"http://www.haskell.org/mailman/listinfo/beginners" target=3D"_bl=
ank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</div></blockquote></div><br></div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href=3D"mailto:Beginners at haskell.org" target=3D"_blank">Beginners at haskel=
l.org</a><br>
<a href=3D"http://www.haskell.org/mailman/listinfo/beginners" target=3D"_bl=
ank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href=3D"mailto:Beginners at haskell.org">Beginners at haskell.org</a><br>
<a href=3D"http://www.haskell.org/mailman/listinfo/beginners" target=3D"_bl=
ank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
--047d7bf0c332b87e7304d6bac33a--
More information about the Beginners
mailing list