plutus icon indicating copy to clipboard operation
plutus copied to clipboard

Fix `isNormalType` and add a test

Open effectfully opened this issue 1 year ago • 0 comments

PlutusCore.Check.Normal is buggy:


>>> :set -XTypeApplications
>>> import PlutusCore.MkPlc
>>> import PlutusCore.Default
>>> import PlutusCore.Check.Normal
>>> import PlutusCore.Normalize
>>> import PlutusCore
>>> isNormalType . unNormalized . runQuote . normalizeType $ mkTyBuiltin @_ @[Integer] @DefaultUni @() @TyName ()
False

We should fix the bug and make isNormalType respect normalization for built-in types which is defined as

normalizeUni :: forall k (a :: k) uni tyname. (HasUniApply uni) => uni (Esc a) -> Type tyname uni ()
normalizeUni uni =
  matchUniApply
    uni
    -- If @uni@ is not an intra-universe application, then we're done.
    (mkTyBuiltinOf () uni)
    -- If it is, then we turn that application into normal type application and recurse
    -- into both the function and its argument.
    (\uniF uniA -> TyApp () (normalizeUni uniF) $ normalizeUni uniA)

Plus we should add a test that normalizeType returns a normal type.

effectfully avatar May 16 '24 13:05 effectfully