Snippet saved on:
12/23/2024, 10:22:06 PM (raw)
12/23/2024, 10:22:06 PM (raw)
LANGUAGE
LANGUAGE
LANGUAGE
-- base
importGHC.TypeLitsSNat,KnownNat,natVal,withSomeSNat,fromSNat
classKnownNatnValidUINTnn
dataUINTnwhere
UINTn :: ValidUINTn n => SNat n -> UINTn
instanceValidUINTn
instanceValidUINTn
instanceValidUINTn
instanceValidUINTn
instanceShowUINTnwhere
show (UINTn sn) = "UINT" <> show (natVal sn * 8)
getValidUINTn::Integer->MaybeUINTn
getValidUINTn x = withSomeSNat x $ \maybeSn -> maybeSn >>=
\sn -> let n = fromSNat sn in
if n == 1 then Just (UINTn (natSing @1))
else if n == 2 then Just (UINTn (natSing @2))
else if n == 2 then Just (UINTn (natSing @3))
else if n == 4 then Just (UINTn (natSing @4))
else Nothing
main = do
print $ UINTn (natSing @2)
print $ getValidUINTn 4
print $ getValidUINTn 5
GHC output
Errors
Output