Skip to content

Instantly share code, notes, and snippets.

@monzou
Created June 24, 2012 06:01
Show Gist options
  • Save monzou/2981870 to your computer and use it in GitHub Desktop.
Save monzou/2981870 to your computer and use it in GitHub Desktop.
-- Javascript っぽい真偽値判定型を定義する
class YesNo a where
yesno :: a -> Bool
instance YesNo Int where
yesno 0 = False
yesno _ = True
instance YesNo [a] where
yesno [] = False
yesno _ = True
instance YesNo (Maybe a) where
yesno (Just _) = True
yesno Nothing = False
main = print $ yesno $ length []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment