2 ms·
Up to isomorphism, yes. That is, you can write a pair of functions that are mutual inverses that witness the fact that those two types are isomorphic: dist
by evincarofautumn 8y ago
Up to isomorphism, yes. That is, you can write a pair of functions that are mutual inverses that witness the fact that those two types are isomorphic:
distl :: (a, Either b c) -> Either (a, b) (a, c)
distl (a, b_c) = case b_c of
Left b -> Left (a, b)
Right c -> Right (a, c)
factl :: Either (a, b) (a, c) -> (a, Either b c)
factl ab_ac = case ab_ac of
Left (a, b) -> (a, Left b)
Right (a, c) -> (a, Right c)
With the “TypeOperators” feature enabled (and “UnicodeSyntax” for pretty arrows and such, because why not), you can write it more literally:
type (×) a b = (a, b)
infixl 7 ×
type (+) a b = Either a b
infixl 6 +
distl ∷ a × (b + c) → a × b + a × c
factl ∷ a × b + a × c → a × (b + c)