[Haskell-cafe] runST $ unsafeIOToST $ ioWhatever

Henning Thielemann lemming at henning-thielemann.de
Sun Apr 14 20:03:17 UTC 2024


On Sun, 14 Apr 2024, Folsk Pratima wrote:

> memSet :: Ptr a -> Word8 -> Word32 -> IO (Ptr a)
> memSet ptr _ 0 = return ptr
> memSet ptr byte size = do
>    let voidptr = castPtr ptr :: Ptr Word8
>        acts =
>            map
>                (\i -> pokeByteOff voidptr i byte)
>                [0 .. fromIntegral (size - 1)]
>    mapM_ id acts
>    return ptr

I think you just want
   pokeArray ptr $ replicate (fromIntegral size) byte


More information about the Haskell-Cafe mailing list