Skip to content

Instantly share code, notes, and snippets.

@andrewthad
Last active June 11, 2018 13:20
Show Gist options
  • Save andrewthad/53c6de3f2937eba51518341466d1418a to your computer and use it in GitHub Desktop.
Save andrewthad/53c6de3f2937eba51518341466d1418a to your computer and use it in GitHub Desktop.
Typeclass dictionary equality test
{-# language BangPatterns #-}
{-# language UnboxedTuples #-}
{-# language TypeInType #-}
{-# language GeneralizedNewtypeDeriving #-}
{-# language TypeApplications #-}
{-# language MagicHash #-}
import Data.Primitive
import GHC.Exts
import Data.Int
main :: IO ()
main = do
putStrLn "Beginning"
let !x = (readByteArray# @Foo)
let !y = (unsafeCoerce# (readByteArray# @Bar))
case reallyUnsafePtrEquality# x y of
1# -> putStrLn "Equal"
_ -> putStrLn "Not Equal"
putStrLn "Finished"
newtype Foo = Foo Int8
deriving (Prim)
newtype Bar = Bar Int8
deriving (Prim)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment