해석없이 직접 locale
정의의 코드를 생성하고 싶습니다. 예 :해석없이 로케일에서 코드 생성
(* A locale, from the code point of view, similar to a class *)
locale MyTest =
fixes L :: "string list"
assumes distinctL: "distinct L"
begin
definition isInL :: "string => bool" where
"isInL s = (s ∈ set L)"
end
가정 사항 MyTest
대한 실행 인스턴스화 그들을
definition "can_instance_MyTest L = distinct L"
lemma "can_instance_MyTest L = MyTest L"
by(simp add: MyTest_def can_instance_MyTest_def)
export_code can_instance_MyTest in Scala file -
I 임의 MyTest
대한 isInL
정의를 실행하는 함수를 정의 할 수 위해 I 코드를 생성 할 수있다.
definition code_isInL :: "string list ⇒ string ⇒ bool option" where
"code_isInL L s = (if can_instance_MyTest L then Some (MyTest.isInL L s) else None)"
lemma "code_isInL L s = Some b ⟷ MyTest L ∧ MyTest.isInL L s = b"
by(simp add: code_isInL_def MyTest_def can_instance_MyTest_def)
그러나, 코드 내보내기 실패
export_code code_isInL in Scala file -
No code equations for MyTest.isInL
가 왜 그런 일을 할 하시겠습니까? 예 : valid_graph
의 문맥에서 locale
으로 작업하고 있습니다. here하지만 한정되어 있습니다. 그래프가 유효한지 테스트하는 것은 쉽습니다. 이제 그래프 알고리즘의 코드를 Scala로 내보내려고합니다. 물론 코드는 임의의 유효한 그래프에서 실행되어야합니다.
나는이 같은 유사 스칼라 비유 생각 해요 :이 불변을 사용하여 데이터 형식 정제입니다 해결하기
class MyTest(L: List[String]) {
require(L.distinct)
def isInL(s: String): Bool = L contains s
}
2 월 (12) CODEGEN - 문서의 2013 버전을 사용하여, §3.3 아니다 매우 이해할 수 있습니다 (첫 문장에서 오타로 시작하는 것 ...). – corny
'morphisms undlist dlist'는 무엇을합니까? – corny
생성 된 코드를 검사하여 뚜렷하지 않은'dlist'를 자유롭게 생성하여'isInL'에 전달할 수 있습니다. 어떻게 예방할 수 있습니까? 나의 원래 예제에서, 코드는 isInL을 실행하기 전에 뚜렷 함을 테스트했다. – corny