Skip to content

Instantly share code, notes, and snippets.

@mpickering
Created March 15, 2019 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpickering/c87616b68d73a89f95adc97971eabc01 to your computer and use it in GitHub Desktop.
Save mpickering/c87616b68d73a89f95adc97971eabc01 to your computer and use it in GitHub Desktop.
{-# LANGUAGE StaticPointers #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE TypeApplications #-}
module SPT where
import GHC.StaticPtr
import Data.Typeable
-- Polymorphic static pointer
foo3 :: Typeable a => StaticPtr (a -> a)
foo3 = static id
-- But now we look it up as `Int -> Int`
foo4 :: IO (Maybe (StaticPtr (Int -> Int)))
foo4 = unsafeLookupStaticPtr (staticKey (foo3 @Bool))
-- And it works fine..
foo5 :: IO Int
foo5 = do
Just sp <- foo4
return $ (deRefStaticPtr sp) 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment