{-# LANGUAGE CPP #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# OPTIONS_GHC -Wall #-}
module ConCat.Sized (Sized(..),genericSize) where
import GHC.Generics
class Sized (f :: * -> *) where
size :: Int
genericSize :: forall f. Sized (Rep1 f) => Int
genericSize :: forall (f :: * -> *). Sized (Rep1 f) => Int
genericSize = forall (f :: * -> *). Sized f => Int
size @(Rep1 f)
{-# INLINABLE genericSize #-}
instance Sized U1 where
size :: Int
size = Int
0
{-# INLINABLE size #-}
instance Sized Par1 where
size :: Int
size = Int
1
{-# INLINABLE size #-}
instance Sized (K1 i c) where
size :: Int
size = Int
0
{-# INLINABLE size #-}
instance Sized f => Sized (M1 i c f) where
size :: Int
size = forall (f :: * -> *). Sized f => Int
size @f
{-# INLINABLE size #-}
instance (Sized g, Sized f) => Sized (g :.: f) where
size :: Int
size = forall (f :: * -> *). Sized f => Int
size @g Int -> Int -> Int
forall a. Num a => a -> a -> a
* forall (f :: * -> *). Sized f => Int
size @f
{-# INLINABLE size #-}
instance (Sized f, Sized g) => Sized (f :*: g) where
size :: Int
size = forall (f :: * -> *). Sized f => Int
size @f Int -> Int -> Int
forall a. Num a => a -> a -> a
+ forall (f :: * -> *). Sized f => Int
size @g
{-# INLINABLE size #-}