-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deriveUniverseSome: Support type variables in constructor argument types #53
Comments
I see. This is somewhat tricky. In a special case of when {-# LANGUAGE GADTs #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# OPTIONS_GHC -ddump-splices #-}
import Data.Some
import Data.Universe
import Data.Universe.Some
import Data.Universe.Helpers
import Data.Universe.Some.TH
import Data.GADT.Show
data Foo a where
MkFoo :: Ordering -> Foo Bool
deriving instance Show (Foo a)
instance GShow Foo where gshowsPrec = showsPrec
data Bar a where
MkBar :: Foo a -> Bool -> Ordering -> Bar a
deriving instance Show (Bar a)
instance GShow Bar where gshowsPrec = showsPrec
deriveUniverseSome ''Foo
instance FiniteSome Foo
-- deriveUniverseSome ''Bar
instance UniverseSome Bar where
universeSome =
withSomeM universeFSome $ \x ->
universeF >>= \y ->
universeF >>= \z ->
[mkSome $ MkBar x y z]
instance FiniteSome Bar where
universeFSome = universeSome
-- prints
-- Some (MkBar (MkFoo LT) False LT)
-- Some (MkBar (MkFoo LT) False EQ)
-- Some (MkBar (MkFoo LT) False GT)
-- Some (MkBar (MkFoo LT) True LT)
-- Some (MkBar (MkFoo LT) True EQ)
-- Some (MkBar (MkFoo LT) True GT)
-- Some (MkBar (MkFoo EQ) False LT)
-- Some (MkBar (MkFoo EQ) False EQ)
-- Some (MkBar (MkFoo EQ) False GT)
-- Some (MkBar (MkFoo EQ) True LT)
-- Some (MkBar (MkFoo EQ) True EQ)
-- Some (MkBar (MkFoo EQ) True GT)
-- Some (MkBar (MkFoo GT) False LT)
-- Some (MkBar (MkFoo GT) False EQ)
-- Some (MkBar (MkFoo GT) False GT)
-- Some (MkBar (MkFoo GT) True LT)
-- Some (MkBar (MkFoo GT) True EQ)
-- Some (MkBar (MkFoo GT) True GT)
--
main :: IO ()
main = mapM_ print (universeSome :: [Some Bar]) There are two points:
we'll run into problem that indexes don't match. Even in this case we can manually show that So I could add Will that be enough? |
This works:
But if you replace that
MkBar
's argument (Int
) withFoo a
, it will fail:The compile error being:
I'd think it should be using the
SomeUniverse Foo
(orUniverse (Some Foo)
) instance instead?The text was updated successfully, but these errors were encountered: