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

Add Homogeneous and HomogeneousRowList for homogeneous rows #20

Merged
merged 8 commits into from
Dec 10, 2017
18 changes: 18 additions & 0 deletions src/Type/Row.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ module Type.Row
, class ListToRow
) where


import Type.Equality (class TypeEquals)


data RProxy (row :: # Type) = RProxy

-- Must not be exported
Expand Down Expand Up @@ -70,3 +74,17 @@ instance listToRowCons
:: ( ListToRow tail tailRow
, RowCons label ty tailRow row )
=> ListToRow (Cons label ty tail) row

-- | Ensure that every field in a row has the same type.
class Homogeneous (row :: # Type) fieldType
Copy link
Contributor

Choose a reason for hiding this comment

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

Also missing a functional dependency here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Am I correct in thinking that the right thing to do here is | row -> fieldType?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add a comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps a value-level function fieldType :: RProxy row -> Proxy fieldType would be handy as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I though I'd asked this already but can't see it now.

Is | row -> fieldType missing here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think so

instance homogeneous
:: ( RowToList row fields
, FieldOf fields fieldType )
=> Homogeneous row fieldType

class FieldOf (rowList :: RowList) fieldType | rowList -> fieldType
instance fieldOfCons
:: ( FieldOf tail fieldType
, TypeEquals fieldType fieldType2 )
=> FieldOf (Cons symbol fieldType tail) fieldType2
instance fieldOfNil :: FieldOf Nil fieldType