Last active
August 29, 2015 13:57
-
-
Save phadej/9370443 to your computer and use it in GitHub Desktop.
Identity in haskell...
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
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 |
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
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