Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loss of referential transparency #12

Open
Nick-Chapman opened this issue Mar 28, 2019 · 0 comments
Open

Loss of referential transparency #12

Nick-Chapman opened this issue Mar 28, 2019 · 0 comments

Comments

@Nick-Chapman
Copy link

The doc for HKey.withKey states:

"The implementation actually creates a key, but because the key cannot escape the given function f, there is no way to observe that if we run withKey f twice, that it will get a different key the second time."

But in the following we see it is possible.

Nick

{-#LANGUAGE ExistentialQuantification, RankNTypes #-}
module Main(main) where

import Data.HMap as HMap

data Wrapped = forall x. Wrapped (HKey x ())

create :: () -> Wrapped
create () = HMap.withKey Wrapped

x,y,z :: Wrapped
x = create ()
y = create ()
z = y

comp :: Wrapped -> Wrapped -> Bool
comp (Wrapped key1) (Wrapped key2) = HMap.unique key1 == HMap.unique key2

main :: IO ()
main = do
  print ("x~y",comp x y)
  print ("x~z",comp x z)
  print ("y~z",comp y z)

{- Prints...
("x~y",False)
("x~z",False)
("y~z",True)
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant