conal / total-map

Finitely represented /total/ maps
Other
15 stars 6 forks source link

DetectableZero instance is non-denotative? #11

Open dmwit opened 4 years ago

dmwit commented 4 years ago

I think for basically the same reasons range can't work (see issue #7), DetectableZero can't work. Some examples to consider:

isZero (fromPartial 0 (M.singleton () 0))
isZero (fromPartial 1 (M.singleton () 0))
isZero (fromPartial 1 (M.empty :: Map Void Int))
dmwit commented 4 years ago

On the more constructive side: I think the fixes available here are basically the same as the fixes available there. One is to add something like

-- | Honor system. Only make an instance if there are infinitely many inhabitants of your type.
class Infinite a

and then make range :: Infinite k => TMap k v -> Set v and instance (Infinite k, Ord k, DetectableZero v) => DetectableZero (TMap k v) essentially without changing the implementations. (Just tweak the M.null check in DetectableZero to the commented-out all check.) The other is to actually iterate over the entire domain; e.g. using the Finite class from the universe package (still essentially the honor system).