You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Domain-types are still a relatively nascent idea for v5 that I am playing around with. I wouldn't use them in anger unless you're ok with updating your code when I change them. Because I will!
Anyway, the updates are:
Improved documentation
Changed their inheritance hierarchy so don't see so many where constraints
DomainType<SELF, REPR> has a base DomainType<SELF>. The derived domain types (Identifier, Locus, VectorSpace, and Amount) inherit from DomainType<SELF>.
So, they don't need to specify a REPR type, simplifying the traits.
It does however mean that you will need to specify the DomainType<SELF, REPR> type as well as whatever derived domain type to gain a constructable value (see the Length example later)
Changed From in DomainType<SELF, REPR> to return a Fin<SELF. This allows for validation when constructing the domain-type.
Because this isn't always desired, you can use an explicitly implemented interface method to override it.
See the Length example below
Dropped the Quantity domain-type for now
I need to find a better approach with C#'s type system
publicreadonlyrecordstructLength(doubleValue):DomainType<Length,double>,//< note this is now needed, because Amount only impl DomainType<Length>Amount<Length,double>{publicstatic Length From(doublerepr)=>new(repr);publicdoubleTo()=>
Value;// explicitly implemented `From`, so it's not part of the Length public interfacestaticFin<Length>DomainType<Length,double>.From(doublerepr)=>new Length(repr);publicstatic Length operator-(Lengthvalue)=>new(-value.Value);publicstatic Length operator+(Lengthleft,Lengthright)=>new(left.Value + right.Value);publicstatic Length operator-(Lengthleft,Lengthright)=>new(left.Value - right.Value);publicstatic Length operator*(Lengthleft,doubleright)=>new(left.Value *right);publicstatic Length operator/(Lengthleft,doubleright)=>new(left.Value /right);publicintCompareTo(Lengthother)=>
Value.CompareTo(other.Value);publicstaticbooloperator>(Lengthleft,Lengthright)=>
left.CompareTo(right)>0;publicstaticbooloperator >=(Lengthleft,Lengthright)=>
left.CompareTo(right) >= 0;publicstaticbooloperator<(Lengthleft,Lengthright)=>
left.CompareTo(right)<0;publicstaticbooloperator <=(Lengthleft,Lengthright)=>
left.CompareTo(right) <= 0;}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Domain-types are still a relatively nascent idea for
v5
that I am playing around with. I wouldn't use them in anger unless you're ok with updating your code when I change them. Because I will!Anyway, the updates are:
where
constraintsDomainType<SELF, REPR>
has a baseDomainType<SELF>
. The derived domain types (Identifier
,Locus
,VectorSpace
, andAmount
) inherit fromDomainType<SELF>
.REPR
type, simplifying the traits.DomainType<SELF, REPR>
type as well as whatever derived domain type to gain a constructable value (see theLength
example later)From
inDomainType<SELF, REPR>
to return aFin<SELF
. This allows for validation when constructing the domain-type.Length
example belowQuantity
domain-type for nowThis discussion was created from the release Domain-types update.
Beta Was this translation helpful? Give feedback.
All reactions