[GHC] #13328: Foldable, Functor, and Traversable deriving handle phantom types badly
GHC
ghc-devs at haskell.org
Fri Feb 24 02:02:02 UTC 2017
#13328: Foldable, Functor, and Traversable deriving handle phantom types badly
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone: 8.4.1
Component: Compiler | Version: 8.1
Resolution: | Keywords: deriving-perf
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by RyanGlScott):
That proposed `foldMap` implementation has different strictness properties
than the current one that `deriving` Foldable uses. That is, this program:
{{{#!hs
{-# LANGUAGE DeriveFoldable #-}
data Phantom a = Z | S (Phantom a)
deriving Foldable
main :: IO ()
main = print $ foldMap (const ()) (undefined :: Phantom Int)
}}}
will throw an exception, whereas this program:
{{{#!hs
data Phantom a = Z | S (Phantom a)
instance Foldable Phantom where
foldMap _ _ = mempty
main :: IO ()
main = print $ foldMap (const ()) (undefined :: Phantom Int)
}}}
will output `()`.
I like the intent of this proposal, however. Can the strictness problem be
fixed by changing it to `foldMap _ !_ = mempty`/`foldr _ z !_ = z`?
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13328#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list