public
Created

  • Download Gist
unsafeCoerce.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
{-# LANGUAGE StandaloneDeriving, FlexibleContexts, UndecidableInstances #-}
-- Laungh ghci with -fobject-code to make the Fix/Tree trick work (thanks edwardk).
 
-- courtesy of hpc on #haskell
import Unsafe.Coerce
import Control.Monad.ST
 
toInteger :: Int -> Integer
isJust :: Maybe a -> Bool
null :: [a] -> Bool
id :: a -> a
 
toInteger = unsafeCoerce
isJust = unsafeCoerce
null = not . unsafeCoerce
id = unsafeCoerce
 
newtype Fix f = Fix (f (Fix f))
deriving instance (Show (Fix f), Show (f (Fix f))) => Show (Fix f)
 
data Tree a = Leaf a | Branch (Tree a) (Tree a)
deriving (Eq, Ord, Show, Read)
 
treeToLists :: Tree a -> Fix []
treeToLists = unsafeCoerce
 
unsafeSTToIO :: ST s a -> IO a
unsafeSTToIO = unsafeCoerce
 
undefined :: a
undefined = unsafeCoerce unsafeCoerce

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.