Skip to content

Instantly share code, notes, and snippets.

@phadej
Last active August 29, 2015 13:57
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 phadej/9370443 to your computer and use it in GitHub Desktop.
Save phadej/9370443 to your computer and use it in GitHub Desktop.
Identity in haskell...
module Main where
import Unsafe.Coerce
-- ideq is strict in its parameters
ideq :: a -> a -> Bool
ideq a b = a `seq` b `seq` aid == bid
where aid = unsafeCoerce a :: Int
bid = unsafeCoerce b :: Int
ones :: [Int]
ones = 1 : ones
yksikaksi :: [Int]
yksikaksi = 1 : 2 : yksikaksi
nan :: Double
nan = 0/0
main :: IO ()
main = do
print $ ones `ideq` ones
print $ ones `ideq` yksikaksi
print $ ones `ideq` tail ones
print $ yksikaksi `ideq` tail yksikaksi
print $ yksikaksi `ideq` tail (tail yksikaksi)
print $ nan == nan
print $ nan `ideq` nan
True
False
True
False
True
False
True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment