싱글 톤 라이브러리를 실험 중이었고 이해할 수없는 경우를 발견했습니다.싱글 톤 라이브러리와 관련하여 두 가지 존재 점에서 KnownNat을 추론 할 수 없습니다.
{-# LANGUAGE GADTs, StandaloneDeriving, RankNTypes, ScopedTypeVariables,
FlexibleInstances, KindSignatures, DataKinds, StandaloneDeriving #-}
import Data.Singletons.Prelude
import Data.Singletons.TypeLits
data Foo (a :: Nat) where
Foo :: Foo a
deriving Show
data Thing where
Thing :: KnownNat a => Foo a -> Thing
deriving instance Show Thing
afoo1 :: Foo 1
afoo1 = Foo
afoo2 :: Foo 2
afoo2 = Foo
athing :: Thing
athing = Thing afoo1
foolen :: forall n. KnownNat n => Foo n -> Integer
foolen foo =
case sing of (SNat :: Sing n) -> natVal (Proxy :: Proxy n)
minfoo :: forall a b c. (Min a b ~ c, KnownNat c) => Foo a -> Foo b -> Integer
minfoo _ _ =
let c = case sing of (SNat :: Sing c) -> natVal (Proxy :: Proxy c)
in natVal (Proxy :: Proxy c)
thinglen :: Thing -> Integer
thinglen (Thing foo) = foolen foo
나는이 두 가지
minthing :: Thing -> Thing -> Integer
minthing (Thing foo1) (Thing foo2) = min (foolen foo1) (foolen foo2)
의 최소를 얻기 위해 사용할 수 그런데 왜 난 그냥이 작업을 수행 할 수없는 이유는 무엇입니까?
minthing' :: Thing -> Thing -> Integer
minthing' (Thing foo1) (Thing foo2) = minfoo foo1 foo2
• Could not deduce (KnownNat
(Data.Singletons.Prelude.Ord.Case_1627967386
a
a1
(Data.Singletons.Prelude.Ord.Case_1627967254
a a1 (GHC.TypeLits.CmpNat a a1))))
나는 이것을 많이하지 않았지만, 나에게 'minfoo'에'(KnownNat, KnownNat b)'가 누락 된 것 같습니다. – Cubic