{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
module Camfort.Helpers.TypeLevel where
import Data.Functor.Identity
import Language.Expression.Pretty
data Some f where
Some :: f a -> Some f
data PairOf f g a = PairOf (f a) (g a)
deriving (PairOf f g a -> PairOf f g a -> Bool
(PairOf f g a -> PairOf f g a -> Bool)
-> (PairOf f g a -> PairOf f g a -> Bool) -> Eq (PairOf f g a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Eq (f a), Eq (g a)) =>
PairOf f g a -> PairOf f g a -> Bool
$c== :: forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Eq (f a), Eq (g a)) =>
PairOf f g a -> PairOf f g a -> Bool
== :: PairOf f g a -> PairOf f g a -> Bool
$c/= :: forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Eq (f a), Eq (g a)) =>
PairOf f g a -> PairOf f g a -> Bool
/= :: PairOf f g a -> PairOf f g a -> Bool
Eq, Eq (PairOf f g a)
Eq (PairOf f g a)
-> (PairOf f g a -> PairOf f g a -> Ordering)
-> (PairOf f g a -> PairOf f g a -> Bool)
-> (PairOf f g a -> PairOf f g a -> Bool)
-> (PairOf f g a -> PairOf f g a -> Bool)
-> (PairOf f g a -> PairOf f g a -> Bool)
-> (PairOf f g a -> PairOf f g a -> PairOf f g a)
-> (PairOf f g a -> PairOf f g a -> PairOf f g a)
-> Ord (PairOf f g a)
PairOf f g a -> PairOf f g a -> Bool
PairOf f g a -> PairOf f g a -> Ordering
PairOf f g a -> PairOf f g a -> PairOf f g a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {k} {f :: k -> *} {g :: k -> *} {a :: k}.
(Ord (f a), Ord (g a)) =>
Eq (PairOf f g a)
forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Ord (f a), Ord (g a)) =>
PairOf f g a -> PairOf f g a -> Bool
forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Ord (f a), Ord (g a)) =>
PairOf f g a -> PairOf f g a -> Ordering
forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Ord (f a), Ord (g a)) =>
PairOf f g a -> PairOf f g a -> PairOf f g a
$ccompare :: forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Ord (f a), Ord (g a)) =>
PairOf f g a -> PairOf f g a -> Ordering
compare :: PairOf f g a -> PairOf f g a -> Ordering
$c< :: forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Ord (f a), Ord (g a)) =>
PairOf f g a -> PairOf f g a -> Bool
< :: PairOf f g a -> PairOf f g a -> Bool
$c<= :: forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Ord (f a), Ord (g a)) =>
PairOf f g a -> PairOf f g a -> Bool
<= :: PairOf f g a -> PairOf f g a -> Bool
$c> :: forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Ord (f a), Ord (g a)) =>
PairOf f g a -> PairOf f g a -> Bool
> :: PairOf f g a -> PairOf f g a -> Bool
$c>= :: forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Ord (f a), Ord (g a)) =>
PairOf f g a -> PairOf f g a -> Bool
>= :: PairOf f g a -> PairOf f g a -> Bool
$cmax :: forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Ord (f a), Ord (g a)) =>
PairOf f g a -> PairOf f g a -> PairOf f g a
max :: PairOf f g a -> PairOf f g a -> PairOf f g a
$cmin :: forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Ord (f a), Ord (g a)) =>
PairOf f g a -> PairOf f g a -> PairOf f g a
min :: PairOf f g a -> PairOf f g a -> PairOf f g a
Ord, Int -> PairOf f g a -> ShowS
[PairOf f g a] -> ShowS
PairOf f g a -> String
(Int -> PairOf f g a -> ShowS)
-> (PairOf f g a -> String)
-> ([PairOf f g a] -> ShowS)
-> Show (PairOf f g a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Show (f a), Show (g a)) =>
Int -> PairOf f g a -> ShowS
forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Show (f a), Show (g a)) =>
[PairOf f g a] -> ShowS
forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Show (f a), Show (g a)) =>
PairOf f g a -> String
$cshowsPrec :: forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Show (f a), Show (g a)) =>
Int -> PairOf f g a -> ShowS
showsPrec :: Int -> PairOf f g a -> ShowS
$cshow :: forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Show (f a), Show (g a)) =>
PairOf f g a -> String
show :: PairOf f g a -> String
$cshowList :: forall k (f :: k -> *) (g :: k -> *) (a :: k).
(Show (f a), Show (g a)) =>
[PairOf f g a] -> ShowS
showList :: [PairOf f g a] -> ShowS
Show, (forall a b. (a -> b) -> PairOf f g a -> PairOf f g b)
-> (forall a b. a -> PairOf f g b -> PairOf f g a)
-> Functor (PairOf f g)
forall a b. a -> PairOf f g b -> PairOf f g a
forall a b. (a -> b) -> PairOf f g a -> PairOf f g b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (f :: * -> *) (g :: * -> *) a b.
(Functor f, Functor g) =>
a -> PairOf f g b -> PairOf f g a
forall (f :: * -> *) (g :: * -> *) a b.
(Functor f, Functor g) =>
(a -> b) -> PairOf f g a -> PairOf f g b
$cfmap :: forall (f :: * -> *) (g :: * -> *) a b.
(Functor f, Functor g) =>
(a -> b) -> PairOf f g a -> PairOf f g b
fmap :: forall a b. (a -> b) -> PairOf f g a -> PairOf f g b
$c<$ :: forall (f :: * -> *) (g :: * -> *) a b.
(Functor f, Functor g) =>
a -> PairOf f g b -> PairOf f g a
<$ :: forall a b. a -> PairOf f g b -> PairOf f g a
Functor, (forall m. Monoid m => PairOf f g m -> m)
-> (forall m a. Monoid m => (a -> m) -> PairOf f g a -> m)
-> (forall m a. Monoid m => (a -> m) -> PairOf f g a -> m)
-> (forall a b. (a -> b -> b) -> b -> PairOf f g a -> b)
-> (forall a b. (a -> b -> b) -> b -> PairOf f g a -> b)
-> (forall b a. (b -> a -> b) -> b -> PairOf f g a -> b)
-> (forall b a. (b -> a -> b) -> b -> PairOf f g a -> b)
-> (forall a. (a -> a -> a) -> PairOf f g a -> a)
-> (forall a. (a -> a -> a) -> PairOf f g a -> a)
-> (forall a. PairOf f g a -> [a])
-> (forall a. PairOf f g a -> Bool)
-> (forall a. PairOf f g a -> Int)
-> (forall a. Eq a => a -> PairOf f g a -> Bool)
-> (forall a. Ord a => PairOf f g a -> a)
-> (forall a. Ord a => PairOf f g a -> a)
-> (forall a. Num a => PairOf f g a -> a)
-> (forall a. Num a => PairOf f g a -> a)
-> Foldable (PairOf f g)
forall a. Eq a => a -> PairOf f g a -> Bool
forall a. Num a => PairOf f g a -> a
forall a. Ord a => PairOf f g a -> a
forall m. Monoid m => PairOf f g m -> m
forall a. PairOf f g a -> Bool
forall a. PairOf f g a -> Int
forall a. PairOf f g a -> [a]
forall a. (a -> a -> a) -> PairOf f g a -> a
forall m a. Monoid m => (a -> m) -> PairOf f g a -> m
forall b a. (b -> a -> b) -> b -> PairOf f g a -> b
forall a b. (a -> b -> b) -> b -> PairOf f g a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g, Eq a) =>
a -> PairOf f g a -> Bool
forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g, Num a) =>
PairOf f g a -> a
forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g, Ord a) =>
PairOf f g a -> a
forall (f :: * -> *) (g :: * -> *) m.
(Foldable f, Foldable g, Monoid m) =>
PairOf f g m -> m
forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g) =>
PairOf f g a -> Bool
forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g) =>
PairOf f g a -> Int
forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g) =>
PairOf f g a -> [a]
forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g) =>
(a -> a -> a) -> PairOf f g a -> a
forall (f :: * -> *) (g :: * -> *) m a.
(Foldable f, Foldable g, Monoid m) =>
(a -> m) -> PairOf f g a -> m
forall (f :: * -> *) (g :: * -> *) b a.
(Foldable f, Foldable g) =>
(b -> a -> b) -> b -> PairOf f g a -> b
forall (f :: * -> *) (g :: * -> *) a b.
(Foldable f, Foldable g) =>
(a -> b -> b) -> b -> PairOf f g a -> b
$cfold :: forall (f :: * -> *) (g :: * -> *) m.
(Foldable f, Foldable g, Monoid m) =>
PairOf f g m -> m
fold :: forall m. Monoid m => PairOf f g m -> m
$cfoldMap :: forall (f :: * -> *) (g :: * -> *) m a.
(Foldable f, Foldable g, Monoid m) =>
(a -> m) -> PairOf f g a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> PairOf f g a -> m
$cfoldMap' :: forall (f :: * -> *) (g :: * -> *) m a.
(Foldable f, Foldable g, Monoid m) =>
(a -> m) -> PairOf f g a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> PairOf f g a -> m
$cfoldr :: forall (f :: * -> *) (g :: * -> *) a b.
(Foldable f, Foldable g) =>
(a -> b -> b) -> b -> PairOf f g a -> b
foldr :: forall a b. (a -> b -> b) -> b -> PairOf f g a -> b
$cfoldr' :: forall (f :: * -> *) (g :: * -> *) a b.
(Foldable f, Foldable g) =>
(a -> b -> b) -> b -> PairOf f g a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> PairOf f g a -> b
$cfoldl :: forall (f :: * -> *) (g :: * -> *) b a.
(Foldable f, Foldable g) =>
(b -> a -> b) -> b -> PairOf f g a -> b
foldl :: forall b a. (b -> a -> b) -> b -> PairOf f g a -> b
$cfoldl' :: forall (f :: * -> *) (g :: * -> *) b a.
(Foldable f, Foldable g) =>
(b -> a -> b) -> b -> PairOf f g a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> PairOf f g a -> b
$cfoldr1 :: forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g) =>
(a -> a -> a) -> PairOf f g a -> a
foldr1 :: forall a. (a -> a -> a) -> PairOf f g a -> a
$cfoldl1 :: forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g) =>
(a -> a -> a) -> PairOf f g a -> a
foldl1 :: forall a. (a -> a -> a) -> PairOf f g a -> a
$ctoList :: forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g) =>
PairOf f g a -> [a]
toList :: forall a. PairOf f g a -> [a]
$cnull :: forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g) =>
PairOf f g a -> Bool
null :: forall a. PairOf f g a -> Bool
$clength :: forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g) =>
PairOf f g a -> Int
length :: forall a. PairOf f g a -> Int
$celem :: forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g, Eq a) =>
a -> PairOf f g a -> Bool
elem :: forall a. Eq a => a -> PairOf f g a -> Bool
$cmaximum :: forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g, Ord a) =>
PairOf f g a -> a
maximum :: forall a. Ord a => PairOf f g a -> a
$cminimum :: forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g, Ord a) =>
PairOf f g a -> a
minimum :: forall a. Ord a => PairOf f g a -> a
$csum :: forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g, Num a) =>
PairOf f g a -> a
sum :: forall a. Num a => PairOf f g a -> a
$cproduct :: forall (f :: * -> *) (g :: * -> *) a.
(Foldable f, Foldable g, Num a) =>
PairOf f g a -> a
product :: forall a. Num a => PairOf f g a -> a
Foldable, Functor (PairOf f g)
Foldable (PairOf f g)
Functor (PairOf f g)
-> Foldable (PairOf f g)
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PairOf f g a -> f (PairOf f g b))
-> (forall (f :: * -> *) a.
Applicative f =>
PairOf f g (f a) -> f (PairOf f g a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PairOf f g a -> m (PairOf f g b))
-> (forall (m :: * -> *) a.
Monad m =>
PairOf f g (m a) -> m (PairOf f g a))
-> Traversable (PairOf f g)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
PairOf f g (m a) -> m (PairOf f g a)
forall (f :: * -> *) a.
Applicative f =>
PairOf f g (f a) -> f (PairOf f g a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PairOf f g a -> m (PairOf f g b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PairOf f g a -> f (PairOf f g b)
forall {f :: * -> *} {g :: * -> *}.
(Traversable f, Traversable g) =>
Functor (PairOf f g)
forall {f :: * -> *} {g :: * -> *}.
(Traversable f, Traversable g) =>
Foldable (PairOf f g)
forall (f :: * -> *) (g :: * -> *) (m :: * -> *) a.
(Traversable f, Traversable g, Monad m) =>
PairOf f g (m a) -> m (PairOf f g a)
forall (f :: * -> *) (g :: * -> *) (f :: * -> *) a.
(Traversable f, Traversable g, Applicative f) =>
PairOf f g (f a) -> f (PairOf f g a)
forall (f :: * -> *) (g :: * -> *) (m :: * -> *) a b.
(Traversable f, Traversable g, Monad m) =>
(a -> m b) -> PairOf f g a -> m (PairOf f g b)
forall (f :: * -> *) (g :: * -> *) (f :: * -> *) a b.
(Traversable f, Traversable g, Applicative f) =>
(a -> f b) -> PairOf f g a -> f (PairOf f g b)
$ctraverse :: forall (f :: * -> *) (g :: * -> *) (f :: * -> *) a b.
(Traversable f, Traversable g, Applicative f) =>
(a -> f b) -> PairOf f g a -> f (PairOf f g b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PairOf f g a -> f (PairOf f g b)
$csequenceA :: forall (f :: * -> *) (g :: * -> *) (f :: * -> *) a.
(Traversable f, Traversable g, Applicative f) =>
PairOf f g (f a) -> f (PairOf f g a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
PairOf f g (f a) -> f (PairOf f g a)
$cmapM :: forall (f :: * -> *) (g :: * -> *) (m :: * -> *) a b.
(Traversable f, Traversable g, Monad m) =>
(a -> m b) -> PairOf f g a -> m (PairOf f g b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PairOf f g a -> m (PairOf f g b)
$csequence :: forall (f :: * -> *) (g :: * -> *) (m :: * -> *) a.
(Traversable f, Traversable g, Monad m) =>
PairOf f g (m a) -> m (PairOf f g a)
sequence :: forall (m :: * -> *) a.
Monad m =>
PairOf f g (m a) -> m (PairOf f g a)
Traversable)
type SomePair f g = Some (PairOf f g)
pattern SomePair :: f a -> g a -> Some (PairOf f g)
pattern $mSomePair :: forall {r} {k} {f :: k -> *} {g :: k -> *}.
Some (PairOf f g)
-> (forall {a :: k}. f a -> g a -> r) -> ((# #) -> r) -> r
$bSomePair :: forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Some (PairOf f g)
SomePair x y = Some (PairOf x y)
traverseSome
:: Functor m
=> (forall a. f a -> m (g a))
-> Some f -> m (Some g)
traverseSome :: forall {k} (m :: * -> *) (f :: k -> *) (g :: k -> *).
Functor m =>
(forall (a :: k). f a -> m (g a)) -> Some f -> m (Some g)
traverseSome forall (a :: k). f a -> m (g a)
f (Some f a
x) = g a -> Some g
forall {k} (f :: k -> *) (a :: k). f a -> Some f
Some (g a -> Some g) -> m (g a) -> m (Some g)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f a -> m (g a)
forall (a :: k). f a -> m (g a)
f f a
x
traversePairOf
:: Functor m
=> (f a -> g a -> m (f' b, g' b))
-> PairOf f g a -> m (PairOf f' g' b)
traversePairOf :: forall {k} {k} (m :: * -> *) (f :: k -> *) (a :: k) (g :: k -> *)
(f' :: k -> *) (b :: k) (g' :: k -> *).
Functor m =>
(f a -> g a -> m (f' b, g' b))
-> PairOf f g a -> m (PairOf f' g' b)
traversePairOf f a -> g a -> m (f' b, g' b)
f (PairOf f a
x g a
y) = (f' b -> g' b -> PairOf f' g' b) -> (f' b, g' b) -> PairOf f' g' b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry f' b -> g' b -> PairOf f' g' b
forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> PairOf f g a
PairOf ((f' b, g' b) -> PairOf f' g' b)
-> m (f' b, g' b) -> m (PairOf f' g' b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f a -> g a -> m (f' b, g' b)
f f a
x g a
y
mapSome :: (forall a. f a -> g a) -> Some f -> Some g
mapSome :: forall {k} (f :: k -> *) (g :: k -> *).
(forall (a :: k). f a -> g a) -> Some f -> Some g
mapSome forall (a :: k). f a -> g a
f = Identity (Some g) -> Some g
forall a. Identity a -> a
runIdentity (Identity (Some g) -> Some g)
-> (Some f -> Identity (Some g)) -> Some f -> Some g
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall (a :: k). f a -> Identity (g a))
-> Some f -> Identity (Some g)
forall {k} (m :: * -> *) (f :: k -> *) (g :: k -> *).
Functor m =>
(forall (a :: k). f a -> m (g a)) -> Some f -> m (Some g)
traverseSome (g a -> Identity (g a)
forall a. a -> Identity a
Identity (g a -> Identity (g a)) -> (f a -> g a) -> f a -> Identity (g a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> g a
forall (a :: k). f a -> g a
f)
instance Pretty1 f => Pretty (Some f) where
prettysPrec :: Int -> Some f -> ShowS
prettysPrec Int
p = \case
Some f a
x -> Int -> f a -> ShowS
forall (a :: k). Int -> f a -> ShowS
forall {k} (t :: k -> *) (a :: k). Pretty1 t => Int -> t a -> ShowS
prettys1Prec Int
p f a
x
instance Pretty1 g => Pretty1 (PairOf f g) where
prettys1Prec :: forall (a :: k). Int -> PairOf f g a -> ShowS
prettys1Prec Int
p = \case
PairOf f a
_ g a
x -> Int -> g a -> ShowS
forall (a :: k). Int -> g a -> ShowS
forall {k} (t :: k -> *) (a :: k). Pretty1 t => Int -> t a -> ShowS
prettys1Prec Int
p g a
x
instance Pretty1 f => Show (Some f) where
show :: Some f -> String
show = Some f -> String
forall a. Pretty a => a -> String
pretty