{-# LANGUAGE GADTs, ScopedTypeVariables #-}
import Data.Typeable
data Foo where
Foo :: (Typeable a, Show a) => a -> Foo
instance Show Foo where
show (Foo a) = show a
fiveFoo :: Foo
fiveFoo = Foo (5 :: Int) -- (Foo 5) doesn't work because of ambiguity
falseFoo :: Foo
falseFoo = Foo False
getFoo :: String -> Foo
getFoo "five" = fiveFoo
getFoo "false" = falseFoo
main = do
print $ getFoo "five" -- prints '5'
print $ getFoo "false" -- prints 'False'