편집: 에 따라 더 구체적인 질문. 감사 answerers 여기에,그리고 나는 생각한 후속 질문가 더 나은 작업의 일부를 설명하는 혼란을 나는 여기에 소개한다.
TL;박사 나를 증거의 제약 조건으로 표현을 사용하는 동안,GADTs 와 존재 제약 조건에서 생성자입니다. (는 심각한 입,죄송합니다!)
나는 증류 문제로 다음과 같습니다. 저는 간단하 GADT 을 나타내는 포인트라고 X
와 기능이라는 응용 프로그램 F
. 포인트 X
로 제한됩 Objects
.
data GADT ix a where
X :: Object ix a => a -> GADT ix a
F :: (a -> b) -> GADT ix a -> GADT ix b
Constrained
말 컨테이너의 개체는 제한에 의해 무언가가 와 Object
는 뭔가. (편집: 나의 진짜 문제가 포함 Category
고 Cartesian
클래스에서 제한된 범주)
-- | I can constrain the values within containers of kind `* -> *`
class Constrained (ix :: * -> *) where
type Object ix a :: Constraint
-- | Here's a trivial constraint. A more interesting one might include `Typeable a`, for ex
instance Constrained (GADT ix) where
type Object (GADT ix) a = (Constrained ix, Object ix a)
나는 다음과 같이 쓰는 표현:
-- error: Could not deduce: Object ix Int arising from a use of ‘X’
ex0 :: GADT ix String
ex0 = F show (X (3 :: Int))
과는 뻔한 솔루션을 작동,빠르게 자세한 정보를 건축할 때 더 큰 표정:
-- Typechecks, but eventually verbose
ex1 :: Object ix Int => GADT ix String
ex1 = F show (X (3 :: Int))
내가 생각하는 올바른 솔루션은 다음과 같이 보일 것입니다:
-- error: Could not deduce: Object ix Int arising from a use of ‘X’
ex2 :: Constrained ix => GADT ix String
ex2 = F show (X (3 :: Int))
하지만 나는 아직도 얻을 수 없다는 증거의 Object ix Int
.
나는 그것의 더 간단하다고 생각하죠. 가 추가하는 조건 Object
제약 조건에서 가족 GADT
클래스의 인스턴스입니다. 가 제공하는 제약 조건에서 표현의 서명이 있습니다. 가 QuantifiedConstraints
지만,나는 확실하지 않다 나는 완전히 파악됩니다. 저를 도와주세요 현명한 그들!
실행 가능:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE InstanceSigs #-}
module Test where
import Data.Kind
import Data.Functor.Identity
import Data.Functor.Const
-- | I can constrain the values within containers of kind `* -> *`
class Constrained (ix :: * -> *) where
type Object ix a :: Constraint
-- | Here's a trivial constraint. A more interesting one might include `Typeable a`, for instance
instance Constrained (GADT ix) where
type Object (GADT ix) a = (Constrained ix, Object ix a)
-- | A demo GADT that has function application ('F'), and points ('X'). The
-- points are constrained.
data GADT ix a where
X :: Object ix a => a -> GADT ix a
F :: (a -> b) -> GADT ix a -> GADT ix b
-- -- Broken
-- -- error: Could not deduce: Object ix Int arising from a use of ‘X’
-- ex0 :: GADT ix String
-- ex0 = F show (X (3 :: Int))
-- Typechecks
-- but for larger programs becomes verbose, requiring many explicit constraints
ex1 :: Object ix Int => GADT ix String
ex1 = F show (X (3 :: Int))
-- -- What I want, but, it's broken
-- ex2 :: Constrained ix => GADT ix String
-- ex2 = F show (X (3 :: Int))
YourFunc
는 것을 소개 톤의 앞을 보일러 플레이트(새로운 전주)하지만,아마도 제거하는 미래를 보일러. WrtInferrenceChain
에,나는 고지도에 나의 문제이지만,아마 후속 설명하는 데 도움이 좋을까? 감사 btw!