[GHC] #13463: Deriving Functor / Foldable / Traversable for co-pattern type

#13463: Deriving Functor / Foldable / Traversable for co-pattern type -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- 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? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13463 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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

#13463: Deriving Functor / Foldable / Traversable for co-pattern type -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature request | Status: closed Priority: low | Milestone: Component: Compiler | Version: 8.0.1 Resolution: wontfix | 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: | -------------------------------------+------------------------------------- Changes (by dfeuer): * priority: normal => low * status: new => closed * resolution: => wontfix Comment: Valid `Functor` instances are always uniquely determined. Valid `Traversable` instances usually aren't, but are they're tightly constrained. `Foldable` is pretty wild; it could shuffle the stream however it liked. In this case, you'd have to come up with a general convention for ordering such things, which seems impractical. The biggest problem here, probably, is that the deriving mechanism only works with one type at a time (indeed, really one constructor at a time). It doesn't dig into other mentioned types at all, and it seems likely quite hard to do so in a consistent way. GADTs only compound the problem. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13463#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13463: Deriving Functor / Foldable / Traversable for co-pattern type -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature request | Status: closed Priority: low | Milestone: Component: Compiler | Version: 8.0.1 Resolution: wontfix | 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: | -------------------------------------+------------------------------------- Comment (by dfeuer): I'm closing this for now; feel free to reopen if you have some idea about implementation. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13463#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC