ekmett / intervals

Interval Arithmetic
http://hackage.haskell.org/package/intervals
BSD 2-Clause "Simplified" License
27 stars 13 forks source link

Distributive instance ? #6

Closed bernstein closed 11 years ago

bernstein commented 11 years ago

I needed a function of type (V3 a -> a) -> V3 (Interval a) -> Interval a which reminded me of cotraverse from distributive. So I added an instance and it does what i want. But is it correct?

instance Distributive Interval where
    distribute f = I (fmap (\(I _ a) -> a) f) (fmap (\(I b _) -> b) f)
    {-# INLINE distribute #-}

If so, is it possible to add it to intervals ?

ekmett commented 11 years ago

Sure. I was seriously considering adding it when I pushed out 0.3, but decided to hesitate until I heard from someone who wanted it. =)

ekmett commented 11 years ago

Your instance flips inf and sup though.

bernstein commented 11 years ago

Thank you very much. I guess i flipped inf and sup because i was to tired to understand what i was doing ;-)

ekmett commented 11 years ago

I'm having trouble getting hackage to accept the upload, but the instance is there in HEAD.

On Thu, Oct 31, 2013 at 4:37 PM, Andreas Bernstein <notifications@github.com

wrote:

Thank your very much. I guess i flipped inf and sup because i was to tired to understand what i was doing ;-)

— Reply to this email directly or view it on GitHubhttps://github.com/ekmett/intervals/issues/6#issuecomment-27525643 .

ekmett commented 11 years ago

Fixed and uploaded.