data Foo a
is defined like:
data Foo a where
Foo :: (Typeable a, Show a) => a -> Foo a
-- perhaps more constructors
instance Show a => Show (Foo a) where
show (Foo a) = show a
with some instances:
fiveFoo :: Foo Int
fiveFoo = Foo 5
falseFoo :: Foo Bool
falseFoo = Foo False
How can I define any function from b -> Foo a
, for example:
getFoo :: (Show a, Typeable a) => String -> Foo a
getFoo "five" = fiveFoo
getFoo "false" = falseFoo
Here getFoo
does not type check with Couldn't match type ‘a’ with ‘Bool’
.
The only thing that I am interested in here is for a
to be of class Show
so I can use getFoo
like:
main = getLine >>= (print . getFoo)