[GHC] #13463: Deriving Functor / Foldable / Traversable for co-pattern type
GHC
ghc-devs at haskell.org
Tue Mar 21 14:11:54 UTC 2017
#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_copattern_matching_in/
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
More information about the ghc-tickets
mailing list