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

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -