Skip to content

Add Parity#27

Merged
garyb merged 2 commits into
masterfrom
parity
Jun 30, 2017
Merged

Add Parity#27
garyb merged 2 commits into
masterfrom
parity

Conversation

@garyb
Copy link
Copy Markdown
Member

@garyb garyb commented Jun 30, 2017

No description provided.

@garyb
Copy link
Copy Markdown
Member Author

garyb commented Jun 30, 2017

Perhaps we can remove even and odd in the future in favour of this, given that Booleans are nearly as bad as Strings as types to be slinging around 😄

Comment thread src/Data/Int.purs
-- | ``` purescript
-- | odd 0 == false
-- | odd 1 == false
-- | odd 1 == true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

😱

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Haha yeah! 😆

Comment thread src/Data/Int.purs
data Parity = Even | Odd

derive instance eqParity :: Eq Parity
derive instance ordParity :: Ord Parity
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe Show too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good thinking. I added Bounded also.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also CommutativeRing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a field, isn't it, if we're going to give it numeric instances? If we treat Parity as Z/2Z with Even = [0] and Odd = [1]?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm thinking of this as being an approximation to integers, not Z/2Z. Dividing an even integer by another even integer could be even or odd.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Although I think sometimes "ring" is defined such that multiplication need only be a semigroup, not necessarily a monoid; in that case you might be able to find two such rings with two elements.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah your logic seems sound to me. I was going from this:

https://en.wikipedia.org/wiki/Finite_ring

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does that suggest that we should give Boolean a Field instance?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we should. Just because it has two elements doesn't mean we should think of it as Z/2 in my opinion. I would rather have a separate type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense, although we can make it into a field without thinking of it as Z/2Z - just by thinking of addition as xor and multiplication as &&. But yeah in the absence of any concrete use case I'm inclined to leave it how it is too.

@garyb garyb merged commit 4ef3a1e into master Jun 30, 2017
@garyb garyb deleted the parity branch June 30, 2017 14:59
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.

3 participants