특정 유형/조건부 IsSet
및 결정 성 기능 isSet
을 정의하는 Idris 모듈이 있습니다. 또한 IsSet
이라는 증명을 얻기 위해 유형 확인시 해당 결정 가능성 함수를 계산하는 몇 가지 도우미 함수를 정의합니다.Idris - 모듈에서 가져온 경우 표현식이 수행되지 않습니다.
Test1.idr
module Test1
import Data.List
%default total
%access export
data IsSet : List t -> Type where
IsSetNil : IsSet []
IsSetCons : Not (Elem x xs) -> IsSet xs -> IsSet (x :: xs)
ifNotSetHereThenNeitherThere : Not (IsSet xs) -> Not (IsSet (x :: xs))
ifNotSetHereThenNeitherThere notXsIsSet (IsSetCons xIsInXs xsIsSet) = notXsIsSet xsIsSet
ifIsElemThenConsIsNotSet : Elem x xs -> Not (IsSet (x :: xs))
ifIsElemThenConsIsNotSet xIsInXs (IsSetCons notXIsInXs xsIsSet) = notXIsInXs xIsInXs
isSet : DecEq t => (xs : List t) -> Dec (IsSet xs)
isSet [] = Yes IsSetNil
isSet (x :: xs) with (isSet xs)
isSet (x :: xs) | No notXsIsSet = No $ ifNotSetHereThenNeitherThere notXsIsSet
isSet (x :: xs) | Yes xsIsSet with (isElem x xs)
isSet (x :: xs) | Yes xsIsSet | No notXInXs = Yes $ IsSetCons notXInXs xsIsSet
isSet (x :: xs) | Yes xsIsSet | Yes xInXs = No $ ifIsElemThenConsIsNotSet xInXs
getYes : (d : Dec p) -> case d of { No _ =>(); Yes _ => p}
getYes (No _) =()
getYes (Yes prf) = prf
getNo : (d : Dec p) -> case d of { No _ => Not p; Yes _ =>()}
getNo (No cnt) = cnt
getNo (Yes _) =()
setTest1 : IsSet ["x"]
setTest1 = getYes $ isSet ["x"]
: 내가 다른 파일에 정의하고 내가 원래 모듈을 가져올 때 모듈 내부에 제대로 보조 기능의 유형 체킹 것을 사용하지만, 그렇지 않은
표현 Test2.idr
module Test2
import Test1
%default total
%access export
setTest2 : IsSet ["x"]
setTest2 = getYes $ isSet ["x"]
setTest1
typechecks 올바르게하지만 setTest2
다음과 같은 오류가 발생합니다 :
When checking right hand side of setTest2 with expected type
IsSet ["x"]
Type mismatch between
case block in getYes at Test1.idr:26:30 (IsSet ["x"])
(isSet ["x"])
(isSet ["x"]) (Type of getYes (isSet ["x"]))
and
IsSet ["x"] (Expected type)
I 유형은 Test2.idr
를 확인해 볼 때 (다만 종류에 반대)
모든 유형과 정의를 전 세계에 공개 할 수 있습니까? 나는'% access export'를 사용하고 있으며, 그것의 의도 된 사용이라고 생각했습니다. '% 액세스 공개 내보내기'를 변경해야할까요? – gonzaw
당신은 할 수 있습니다. 그래도 잠시 생각해 보시길 바랍니다. '공개 수출 (public export) '은 물건의 정의 **를 드러내는 데, 이는 모듈에 대한 생각과 다소 반대되는 것, 즉 구현 세부 사항을 숨기는 것입니다. [documentation] (http://docs.idris-lang.org/en/latest/tutorial/modules.html)에서 이에 대해 말해야하는 것을 참조해야합니다. –
아, 나는 그것을 시도 할 것이다. 의존적 인 타입을 가진 것은 당신이 실제로 어떤 타입 레벨 계산을위한 정의가 필요한지 아닌지를 알지 못한다는 것입니다 : P – gonzaw