4 ms·
And now for exercise 2: Port the solution to Haskell
by peterkelly 13y ago
And now for exercise 2:
Port the solution to Haskell
- deleted 13y ago[deleted]
- chrra 13y agonewtype X = X (IORef Int) instance Num X where fromInteger = X . unsafePerformIO . newIORef . fromInteger instance Eq X where (X a) == (X b) = unsafePerformIO $ do x <- readIORef a y <- readIORef b writeIORef a $ x+1 return $ x == y ghci> a <- fmap X $ newIORef 1 ghci> a == 1 && a == 2 True Edit: formatting.
- okasaki 13y agoeven more general: let a = 1; _ == _ = True in a == 1 && a == 2