
#13463: Deriving Functor / Foldable / Traversable for co-pattern type -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by Iceland_jack: Old description:
This is probably asking too much, but could GHC derive `Functor`, `Foldable` ... for this [https://www.reddit.com/r/haskell/comments/4aju8f/simple_example_of_emulating... co-pattern] data type?
{{{#!hs data ListTag :: Type -> Type -> Type where HeadTag :: ListTag a a TailTag :: ListTag a (Stream a)
newtype Stream a = S (forall res. ListTag a res -> res)
instance Functor Stream where fmap :: (a -> a') -> (Stream a -> Stream a') fmap f (S stream) = S $ \case HeadTag -> f (stream HeadTag) TailTag -> fmap f (stream TailTag)
instance Foldable Stream where foldMap :: Monoid m => (a -> m) -> (Stream a -> m) foldMap f (S stream) = f (stream HeadTag) <> foldMap f (stream TailTag) }}}
I'm guessing it's not worth it in any case, but is it uniquely determined?
New description: This is probably asking too much, but could GHC derive `Functor`, `Foldable` ... for this [https://www.reddit.com/r/haskell/comments/4aju8f/simple_example_of_emulating... co-pattern] data type? {{{#!hs data StreamTag :: Type -> Type -> Type where HeadTag :: StreamTag a a TailTag :: StreamTag a (Stream a) newtype Stream a = S (forall res. StreamTag a res -> res) instance Functor Stream where fmap :: (a -> a') -> (Stream a -> Stream a') fmap f (S stream) = S $ \case HeadTag -> f (stream HeadTag) TailTag -> fmap f (stream TailTag) instance Foldable Stream where foldMap :: Monoid m => (a -> m) -> (Stream a -> m) foldMap f (S stream) = f (stream HeadTag) <> foldMap f (stream TailTag) }}} I'm guessing it's not worth it in any case, but is it uniquely determined? -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13463#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler