[Haskell-cafe] mdo with multiple values
Joachim Breitner
mail at joachim-breitner.de
Thu Jan 16 10:49:09 UTC 2014
Hi,
Am Donnerstag, den 16.01.2014, 11:34 +0100 schrieb Heinrich Apfelmus:
> Fortunately, we do known the spine of `offsets` in advance: it has the
> same spine as `byteStrings`. The solution is to make that explicit in
> the code, by using a lazy `zip`:
>
> ...
> mapM_ putWord32 (offsets `spine` byteStrings)
> ...
>
> where
> spine :: [a] -> [void] -> [a]
> spine ~[] [] = []
> spine ~(x:xs) (y:ys) = x : tag xs ys
>
> This code takes the spine of `byteStrings` and fills it with values from
> `offsets`.
I thought about something in that direction; but thanks for working it
out.
What I do not like about this solution is that it is not safe: As a
programmer I have two make sure that offsets and byteStrings actually
have the same length.
Greetings,
Joachim
--
Joachim Breitner
e-Mail: mail at joachim-breitner.de
Homepage: http://www.joachim-breitner.de
Jabber-ID: nomeata at joachim-breitner.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140116/786f0d56/attachment.sig>
More information about the Haskell-Cafe
mailing list