5 | import public Data.DEq
6 | import public Data.DOrd
7 | import public Data.DShow
8 | import public Data.Some
14 | data DSum : (tag : a -> Type) -> (f : a -> Type) -> Type where
15 | (:=>) : {0 x : a} -> tag x -> f x -> DSum tag f
19 | fst : DSum tag f -> Some tag
20 | fst (x :=> y) = MkSome x
24 | snd : DSum tag f -> Some f
25 | snd (x :=> y) = MkSome y
29 | toSome : DSum tag f -> Some (\x => (tag x, f x))
30 | toSome (x :=> y) = MkSome (x, y)
33 | implementation (tagimpl : DEq tag) => (fimpl : DEq f) => Eq (DSum tag f) where
34 | (x :=> y) == (x' :=> y') = deq' @{tagimpl} x x' && deq' @{fimpl} y y'
37 | implementation (tagimpl : DOrd tag) => (fimpl : DOrd f) => Ord (DSum tag f) where
38 | compare (x :=> y) (x' :=> y') = case dcompare @{tagimpl} x x' of
41 | DEQ => dcompare' @{fimpl} y y'
44 | implementation (tagimpl : DShow tag) => (fimpl : DShow f) => Show (DSum tag f) where
46 | show (x :=> y) = let
47 | noParens = unwords [dshow x @{tagimpl}, ":=>", dshow y @{fimpl}]
48 | in showParens True noParens