Skip to content

Instantly share code, notes, and snippets.

@bitonic
Created February 28, 2012 18:32
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bitonic/1934179 to your computer and use it in GitHub Desktop.
Save bitonic/1934179 to your computer and use it in GitHub Desktop.
{-# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment