Skip to content

Instantly share code, notes, and snippets.

@monadplus
Created March 2, 2019 22:13
Show Gist options
  • Save monadplus/9e590a39b423139244fcdc81ee743e1f to your computer and use it in GitHub Desktop.
Save monadplus/9e590a39b423139244fcdc81ee743e1f to your computer and use it in GitHub Desktop.
Existentially qualified types in Scala
/*
data ShowBox = forall s. Show s => SB s
heteroList :: [ShowBox]
heteroList = [SB (), SB 5, SB True]
-----
instance Show ShowBox where
show (SB s) = show s
f :: [ShowBox] -> IO ()
f xs = mapM_ print xs
main = f heteroList
*/
def show(as : List[F[_]] forSome { type F[_] <: Show[_]}): IO[String] =
as.traverse(a => IO.pure(a.show(_)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment