Skip to content

Instantly share code, notes, and snippets.

@eagletmt
Forked from ujihisa/gist:463997
Created July 5, 2010 06:46
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 eagletmt/464078 to your computer and use it in GitHub Desktop.
Save eagletmt/464078 to your computer and use it in GitHub Desktop.
{-# LANGUAGE ExistentialQuantification #-}
import System
class Hi_ a where
hi :: a -> String
data Hi = forall a. Hi_ a => Hi a
instance Hi_ Hi where
hi (Hi x) = hi x
data Ujihisa = Ujihisa
instance Hi_ Ujihisa where
hi = const "my name is ujihisa"
ujihisa :: Hi
ujihisa = Hi Ujihisa
data Ujm = Ujm
instance Hi_ Ujm where
hi = const "this is a pen"
ujm :: Hi
ujm = Hi Ujm
main = do x <- getArgs
let the_klass = if length x == 1 then ujihisa else ujm
print $ hi the_klass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment