module Util.Fcf
  ( Over2
  , type (<|>)
  , TyEqSing
  ) where

import Fcf
import Data.Singletons.Prelude.Eq (DefaultEq)

data Over2 :: (a -> b -> Exp r) -> (x -> Exp a) -> (x -> Exp b) -> x -> Exp r
type instance Eval (Over2 f g h x) = Eval (LiftM2 f (g x) (h x))

data (<|>) :: f a -> f a -> Exp (f a)
type instance Eval ('Nothing <|> m) = m
type instance Eval ('Just x <|> _) = 'Just x

-- | Similar to 'TyEq', but compares types via @DefaultEq@ used in singletons
-- comparisons (see "Data.Singletons.Prelude.Eq" module).
data TyEqSing :: a -> b -> Exp Bool
type instance Eval (TyEqSing a b) = DefaultEq a b