Created
October 14, 2011 11:26
-
-
Save andy-morris/1286858 to your computer and use it in GitHub Desktop.
purity police, arrest this man
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
{-# 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" |
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
Chuck Norris exceptions really seems to be popular now...
https://github.com/criso/ChuckNorrisException