In some respects, I think both vinyl and hlist are more general. But I could be wrong.
On Saturday, June 7, 2014, Ben Foppa <benjamin.foppa@gmail.com> wrote:
Hi cafe. On a use case whim, I made the open-union package (https://github.com/RobotGymnast/open-union), copying the basic idea from extensible-effects:Data.OpenUnion1. I haven't uploaded to hackage yet, on the chance that there's already something like this around. Here's the basic functionality:If any of the (@>) cases is omitted, a compile-time error occurs. If you try to lift a bad value to the union, a compile-time error occurs.
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE ScopedTypeVariables #-} import Data.OpenUnion type MyUnion = Union (Char :| Int :| [()] :| Void) showMyUnion :: MyUnion -> String showMyUnion = (\(c :: Char) -> "char: " ++ show c) @> (\(i :: Int) -> "int: " ++ show i) @> (\(l :: [()]) -> "list length: " ++ show (length l)) @> typesExhausted main :: IO () main = do putStrLn $ showMyUnion $ liftUnion (4 :: Int) putStrLn $ showMyUnion $ liftUnion 'a' putStrLn $ showMyUnion $ liftUnion [(), ()]
Any thoughts? Is there already something like this around?