Skip to content

Instantly share code, notes, and snippets.

@andy-morris
Created October 14, 2011 11:26
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 andy-morris/1286858 to your computer and use it in GitHub Desktop.
Save andy-morris/1286858 to your computer and use it in GitHub Desktop.
purity police, arrest this man
{-# LANGUAGE DeriveDataTypeable #-}
module CNEx where
import Prelude hiding (catch)
import Data.Typeable
import Control.Exception
import System.Random
import System.IO.Unsafe
data ChuckNorris = ChuckNorris deriving (Typeable)
instance Show ChuckNorris where
{-# NOINLINE show #-}
show _ = unsafePerformIO $ do
i <- randomRIO (0, length phrases - 1)
return $ phrases !! i
where phrases =
["You cannot throw Chuck Norris... Chuck Norris throws YOU!",
"Chuck Norris wrote Hello World once... it was called Unix",
"Chuck Norris will functionally KICK YOUR ASS"]
instance Exception ChuckNorris where
toException = SomeException
fromException _ = Nothing -- nope
test =
throw ChuckNorris
`catch` \ChuckNorris -> error "can't be caught"
@md2perpe
Copy link

Chuck Norris exceptions really seems to be popular now...
https://github.com/criso/ChuckNorrisException

@andy-morris
Copy link
Author

Haha, that’s what I was referencing. :3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment