<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>You are strict in your definition of `sizeOf`. You probably want:<br></div><div><br></div><div> sizeOf ~<span class="pl-ent">SignedMessage</span>{messageLength} = ...<br></div><div><br></div><div>On Mon, 28 Nov 2022, at 4:04 PM, Hécate wrote:<br></div><blockquote type="cite" id="qt" style=""><div>Hi everyone,<br></div><div><br></div><div>In a fit of madness I have found myself writing Haskell code where I <br></div><div>need to implement a Storable instance. However, by virtue of not being a <br></div><div>C programmer, I'm fairly lost on some of the details, especially the <br></div><div>value of the sizeOf and alignment methods.<br></div><div><br></div><div>My Haskell-level record is the following:<br></div><div><br></div><div>data SignedMessage = SignedMessage<br></div><div> { messageLength :: CSize<br></div><div> , messageForeignPtr :: ForeignPtr CUChar<br></div><div> , signatureForeignPtr :: ForeignPtr CUChar<br></div><div> }<br></div><div><br></div><div><br></div><div>Here is the code of the Storable instance: <br></div><div><a href="https://gist.github.com/Kleidukos/31346d067f309f2a86cbd97a85c0f1e8#file-signing-hs">https://gist.github.com/Kleidukos/31346d067f309f2a86cbd97a85c0f1e8#file-signing-hs</a><br></div><div><br></div><div>And so I used `hedgehog-classes` to test the Storable instance. However, <br></div><div>all the tests fail with the same reason: Prelude.undefined:<br></div><div><br></div><div><a href="https://gist.github.com/Kleidukos/31346d067f309f2a86cbd97a85c0f1e8#file-undefined_error-txt">https://gist.github.com/Kleidukos/31346d067f309f2a86cbd97a85c0f1e8#file-undefined_error-txt</a><br></div><div><br></div><div>The main problem (and that's certainly a red herring for me) is that the <br></div><div>`undefined` call comes frombase:Foreign.Marshal.Array.<br></div><div>Which shouldn't be a problem, as it is not supposed to be evaluated!<br></div><div>Yet apparently it is.<br></div><div><br></div><div>If you're interested to see the full code, it's located here: <br></div><div><a href="https://github.com/haskell-cryptography/libsodium-bindings/blob/add-sel-package/sel/src/Sel/Signing.hs">https://github.com/haskell-cryptography/libsodium-bindings/blob/add-sel-package/sel/src/Sel/Signing.hs</a><br></div><div><br></div><div>I'm not sure how to proceed from here. What would be a good angle to <br></div><div>approach this?<br></div><div><br></div><div>Cheers,<br></div><div>Hécate<br></div><div><br></div><div>-- <br></div><div>Hécate ✨<br></div><div>🐦: @TechnoEmpress<br></div><div>IRC: Hecate<br></div><div>WWW: <a href="https://glitchbra.in">https://glitchbra.in</a><br></div><div>RUN: BSD<br></div><div><br></div><div>_______________________________________________<br></div><div>Haskell-Cafe mailing list<br></div><div>To (un)subscribe, modify options or view archives go to:<br></div><div><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br></div><div>Only members subscribed via the mailman list are allowed to post.<br></div></blockquote><div><br></div></body></html>