Skip to content

Instantly share code, notes, and snippets.

@folone
Forked from bitonic/unsafeCoerce.hs
Created February 29, 2012 08:59
Show Gist options
  • Save folone/1939299 to your computer and use it in GitHub Desktop.
Save folone/1939299 to your computer and use it in GitHub Desktop.
-- 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))
data Tree a = Leaf a | Branch (Tree a) (Tree a)
treeToLists :: Tree a -> Fix []
treeToLists = unsafeCoerce
unsafeSTToIO :: ST s a -> IO a
unsafeSTToIO = unsafeCoerce
undefined :: a
undefined = unsafeCoerce unsafeCoerce
fixSTM :: (a -> STM a) -> STM a
fixSTM = unsafeCoerce fixIO
isTrue :: Bool -> Bool
isTrue = (unsafeCoerce :: Either a b -> Bool) . (unsafeCoerce :: Maybe c -> Either a b) . (unsafeCoerce :: Bool -> Maybe c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment