Closed wpoosanguansit closed 5 years ago
Hi,
You can do it as follows:
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Haskus.Utils.Variant
import Haskus.Utils.Types
import Haskus.Utils.Types.List
variantSize :: forall xs. (KnownNat (Length xs)) => V xs -> Word
variantSize _ = natValue @(Length xs)
Test:
> data A
> data B
> data C
> data D
> let v = undefined :: V '[A,B,C,D]
> variantSize v
4
Thank you.
On Jan 8, 2019, at 9:55 AM, Sylvain Henry notifications@github.com wrote:
Hi,
You can do it as follows:
{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ScopedTypeVariables #-}
import Haskus.Utils.Variant import Haskus.Utils.Types import Haskus.Utils.Types.List
variantSize :: forall xs. (KnownNat (Length xs)) => V xs -> Word variantSize _ = natValue @(Length xs) Test:
data A data B data C data D let v = undefined :: V '[A,B,C,D] variantSize v 4 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
You're welcome. As it can be useful to others, I've added it for the next release.
Hi,
I am trying out the Variant code and I am curious if there is a way to check the size of the Variant types, not the size of the value.
for v :: V '[A, B, C, D] I would like to to get the size of 4 out. Thank you for your help.