Created
March 15, 2019 13:30
-
-
Save mpickering/c87616b68d73a89f95adc97971eabc01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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