[Haskell-cafe] Categorical description for vector-space instance of AdditiveGroup (Maybe a)
trevor cook
trevor.j.cook at gmail.com
Wed Sep 10 16:20:12 UTC 2014
Here's that vector-space code, formatted better.
-- Maybe is handled like the Maybe-of-Sum monoid
instance AdditiveGroup a => AdditiveGroup (Maybe a) where
zeroV = Nothing Nothing ^+^ b' = b'
a' ^+^ Nothing = a'
Just a' ^+^ Just b' = Just (a' ^+^ b')
negateV = fmap negateV
{- Alexey Khudyakov wrote:
I looked through vector-space package and found lawless instance. Namely
Maybe's AdditiveGroup instance It's group so following relation is
expected to hold. Otherwise it's not a group.
> x ^+^ negateV x == zeroV
Here is counterexample:
> let x = Just 2 in x ^+^ negateV x == zeroV
False
I think it's not possible to sensibly define group instance for Maybe a at
all.I see that the problem here is in distinguishing 'Just zeroV'
fromNothing. I could fix the Just + Just line to use Nothing instead of
JustzeroV when a' ^+^ b' == zeroV, although doing so would require Eq a
andhence lose some generality. Even so, the abstraction leak would
probablyshow up elsewhere.Hm.
-}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140910/8664680c/attachment.html>
More information about the Haskell-Cafe
mailing list