Skip to content

Instantly share code, notes, and snippets.

@TerrorJack
Last active May 12, 2025 18:08
Show Gist options
  • Save TerrorJack/5acc93660ba8669ad4f1f2f7989d9d03 to your computer and use it in GitHub Desktop.
Save TerrorJack/5acc93660ba8669ad4f1f2f7989d9d03 to your computer and use it in GitHub Desktop.
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
module Spark where
import GHC.Exts
import GHC.ST
spark :: a -> ST s a
spark x' = ST $ \s0 -> case spark# x s0 of
(# s1, r #) -> (# s1, r #)
where
x = runRW# $ \s0 -> case noDuplicate# s0 of
_ -> lazy x'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment