Mixed Fraction data type

I'm looking at Sandy Maguire's _Thinking With Types_ and he's talking about the cardinality of types. He introduces the product type data MixedFraction a = Fraction { mixedBit :: Word8 , numerator :: a , denominator :: a } How is this a type for holding mixed fractions such as 5-1/2? ⨽ Lawrence Bottorff Grand Marais, MN, USA borgauf@gmail.com

From context it's only used as a more concrete example of a product type to show how cardinality analysis works. I would infer that the idea is that this type would use mixedBit for the whole number and there would be a constraint that numerator < denominator. Fraction 5 1 2 would be the canonical way to represent 5 1/2 in that scheme. Practically speaking there's no reason to have the mixedBit field because a pair is enough to represent any fraction, but if it was simplified this way then the example would be redundant since there's already an example of a pair type on the same page.
On Tue, Sep 14, 2021 at 8:51 PM Galaxy Being
I'm looking at Sandy Maguire's _Thinking With Types_ and he's talking about the cardinality of types. He introduces the product type
data MixedFraction a = Fraction { mixedBit :: Word8 , numerator :: a , denominator :: a }
How is this a type for holding mixed fractions such as 5-1/2?
⨽ Lawrence Bottorff Grand Marais, MN, USA borgauf@gmail.com _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Guess I was just wondering what deep lore was behind choosing Word8 for the
whole number instead of an Integer. Right, Fraction 5 1 2, but what's up
with "mixedBit" and Word8? BTW, how might that constraint numerator <
denominator be handled if setting up MIxedFraction for real use?
On Tue, Sep 14, 2021 at 11:13 PM Bob Ippolito
From context it's only used as a more concrete example of a product type to show how cardinality analysis works. I would infer that the idea is that this type would use mixedBit for the whole number and there would be a constraint that numerator < denominator. Fraction 5 1 2 would be the canonical way to represent 5 1/2 in that scheme. Practically speaking there's no reason to have the mixedBit field because a pair is enough to represent any fraction, but if it was simplified this way then the example would be redundant since there's already an example of a pair type on the same page.
On Tue, Sep 14, 2021 at 8:51 PM Galaxy Being
wrote: I'm looking at Sandy Maguire's _Thinking With Types_ and he's talking about the cardinality of types. He introduces the product type
data MixedFraction a = Fraction { mixedBit :: Word8 , numerator :: a , denominator :: a }
How is this a type for holding mixed fractions such as 5-1/2?
⨽ Lawrence Bottorff Grand Marais, MN, USA borgauf@gmail.com _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- ⨽ Lawrence Bottorff Grand Marais, MN, USA borgauf@gmail.com

I don't think there's any deep lore, it doesn't really make much sense to
specialize the mixedBit but not the numerator and denominator. I think it
was just an example to show that the cardinality is 256 * |a| * |a|.
With that representation, constraints can only be enforced with a smart
constructor. https://wiki.haskell.org/Smart_constructors
On Wed, Sep 15, 2021 at 7:35 AM Galaxy Being
Guess I was just wondering what deep lore was behind choosing Word8 for the whole number instead of an Integer. Right, Fraction 5 1 2, but what's up with "mixedBit" and Word8? BTW, how might that constraint numerator < denominator be handled if setting up MIxedFraction for real use?
On Tue, Sep 14, 2021 at 11:13 PM Bob Ippolito
wrote: From context it's only used as a more concrete example of a product type to show how cardinality analysis works. I would infer that the idea is that this type would use mixedBit for the whole number and there would be a constraint that numerator < denominator. Fraction 5 1 2 would be the canonical way to represent 5 1/2 in that scheme. Practically speaking there's no reason to have the mixedBit field because a pair is enough to represent any fraction, but if it was simplified this way then the example would be redundant since there's already an example of a pair type on the same page.
On Tue, Sep 14, 2021 at 8:51 PM Galaxy Being
wrote: I'm looking at Sandy Maguire's _Thinking With Types_ and he's talking about the cardinality of types. He introduces the product type
data MixedFraction a = Fraction { mixedBit :: Word8 , numerator :: a , denominator :: a }
How is this a type for holding mixed fractions such as 5-1/2?
⨽ Lawrence Bottorff Grand Marais, MN, USA borgauf@gmail.com _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- ⨽ Lawrence Bottorff Grand Marais, MN, USA borgauf@gmail.com
participants (2)
-
Bob Ippolito
-
Galaxy Being