
I endup with this solution, whcih is for me quite elegant. Maybe this could be generalize with the singleton package. mkSomeDataCollection :: DataCollection a b -> SomeDataCollection mkSomeDataCollection c = withSCollectType $ \s -> withSCollectSourceFormat $ \f -> SomeDataCollection s f (coerce c) where withSCollectType :: (forall c. SCollectType c -> SomeDataCollection) -> SomeDataCollection withSCollectType cont = if "ref-" `isPrefixOf` imagePrefix c then cont SCaracterization else cont SCollect withSCollectSourceFormat :: (forall c .SCollectSourceFormat c -> SomeDataCollection) -> SomeDataCollection withSCollectSourceFormat cont = case imageSuffix c of (Just "cbf") -> cont SCbf (Just "h5") -> cont SHdf5 (Just _) -> cont SCbf Nothing -> cont SCbf I can not use singleton since I decided to stick to Debian stable/unstable Cheers and thanks a lot for the help. Frederic