Haskell: Is it possible to create a list of Show types? List[Show]? -
is possible create list holds values belong show type ?
this similar list[showable] in scala, showable trait.
in way 1 put, example, int , string same list.
is possible? if yes, how ?
you can using existential types
data showbox = forall s. show s => sb s heterolist :: [showbox] heterolist = [sb "hello world", sb 5, sb 1] the thing can items in list show them:
let strings = fmap (\(sb b) -> show b) heterolist
Comments
Post a Comment