Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract away the interface of Interval from the rest of the module #2

Merged
merged 3 commits into from Mar 6, 2019
Merged

Abstract away the interface of Interval from the rest of the module #2

merged 3 commits into from Mar 6, 2019

Conversation

Bodigrim
Copy link
Collaborator

I've been playing with different implementations of Interval and it appeared to be useful to do not pattern-match on Interval constructor in the body of the module, relying solely on lowerBound' / upperBound' / empty / interval.

It would be even better to move definition of Interval to a separate module, but it is difficult because of Lattice instances.

What is your opinion on this?

@Bodigrim
Copy link
Collaborator Author

Ping?

@msakai
Copy link
Owner

msakai commented Mar 2, 2019

Thank you for your PR, and sorry for the late reply.
I agree with you that it's better to avoid pattern-match on Interval constructor.

It would be even better to move definition of Interval to a separate module, but it is difficult because of Lattice instances.

Do you worry about moving the definition of Interval type to a separate module while leaving functions and Lattice instances in the original module makes those instances orphan instances?
I think it is okay to use -fno-warn-orphans if the change makes the code easier to maintain.

, -- | 'upperBound' of the interval and whether it is included in the interval.
-- The result is convenient to use as an argument for 'interval'.
upperBound' :: !(Extended r, Bool)
} deriving (Eq, Generic, Data, Typeable)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR replaces hand-written Data instance with the one generated by GHC.
But doesn’t the generated one allow constructing unnormalized interval value (e.g. through gmapT)?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that following y becomes unnormalized interval where lower bounds is Finite (-1) while upper bound is Finite 0.

{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.Interval as Interval
import Data.Data
import Data.Maybe

f :: Data a => a -> a
f x = fromJust $ do
  (x' :: Interval.Extended Integer, b::Bool) <- cast x
  cast (fmap negate x', b)

x :: Interval.Interval Integer
x = 0 Interval.<=..<= 1

y :: Interval.Interval Integer
y = gmapT f x

So could you revert this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, my bad.

@msakai
Copy link
Owner

msakai commented Mar 4, 2019

Other changes looks good to me.

@Bodigrim
Copy link
Collaborator Author

Bodigrim commented Mar 4, 2019

Thanks, please take another look.

Copy link
Owner

@msakai msakai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@msakai msakai merged commit 1f3609c into msakai:master Mar 6, 2019
@msakai
Copy link
Owner

msakai commented Mar 6, 2019

Thank you very much for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants