3 | import public Data.DEq
4 | import public Data.DOrd
5 | import public Data.DShow
11 | data Some : (f : t -> Type) -> Type where
15 | MkSome : {0 a : t} -> (x : f a) -> Some f
18 | implementation (impl : DEq f) => Eq (Some f) where
19 | MkSome x == MkSome y = deq' x y @{impl}
22 | implementation (impl : DOrd f) => Ord (Some f) where
23 | compare (MkSome x) (MkSome y) = case dcompare x y @{impl} of
29 | implementation (impl : DShow f) => Show (Some f) where
30 | showPrec prec (MkSome fx) = showCon prec "MkSome" (dshowArg fx @{impl})
35 | withSome : Some f -> ({0 x : a} -> f x -> b) -> b
36 | withSome (MkSome thing) some = some thing
40 | withSomeM : Monad m => m (Some f) -> ({0 x : a} -> f x -> m b) -> m b
41 | withSomeM m k = m >>= (\s => withSome s k)
45 | foldSome : ({0 a : t} -> tag a -> b) -> Some tag -> b
46 | foldSome some (MkSome thing) = some thing
50 | map : ({0 a : t} -> f a -> g a) -> Some f -> Some g
51 | map f (MkSome x) = MkSome (f x)
55 | traverseSome : Functor m => ({0 a : t} -> f a -> m (g a)) -> Some f -> m (Some g)
56 | traverseSome f (MkSome x) = map MkSome (f x)
59 | implementation Applicative m => Semigroup (Some m) where
60 | MkSome mx <+> MkSome my = MkSome (mx *> my)
63 | implementation Applicative m => Monoid (Some m) where
64 | neutral = MkSome (pure ())