{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE TypeOperators #-}
#ifdef KNOWABLE
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
#endif
{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}
module ConCat.Known where
import GHC.TypeLits
import Data.Constraint
#define KNOW(nm,op) \
nm :: (KnownNat m, KnownNat n) :- KnownNat (m op n) ; \
nm = Sub Dict
KNOW(knownAdd,+)
KNOW(knownMul,GHC.TypeLits.*)
#ifdef KNOWABLE
class KnowableNat n where knownNat :: Dict (KnownNat n)
instance {-# OVERLAPPABLE #-} KnownNat n => KnowableNat n where knownNat = Dict
type KnowableNat2 m n = (KnowableNat m, KnowableNat n)
instance KnowableNat2 m n => KnowableNat (m + n) where knownNat = Dict \\ knownAdd @m @n
instance KnowableNat2 m n => KnowableNat (m * n) where knownNat = Dict \\ knownMul @m @n
#endif