store icon indicating copy to clipboard operation
store copied to clipboard

Decidable and Divisible instances for Size

Open lambda-fairy opened this issue 8 years ago • 1 comments

The Size type can implement Divisible:

instance Divisible Size where
    divide f = combineSizeWith (fst . f) (snd . f)
    conquer = ConstSize 0

I think it can implement Decidable as well, though I'm not sure if my code is correct (or useful):

instance Decidable Size where
    choose f s t = VarSize (either (getSizeWith s) (getSizeWith t) . f)
    lose f = VarSize (absurd . f)

lambda-fairy avatar Sep 14 '17 10:09 lambda-fairy

Interesting! Seems potentially useful, feel free to open a PR. I think the Decidable instance could be useful, for computing the size of the encoding of a sum type.

mgsloan avatar Sep 15 '17 03:09 mgsloan