# HG changeset patch # User nipkow # Date 1180157163 -7200 # Node ID f5de7da165bb1e2f147358691efe94f35624ea4c # Parent 669d7391df1a1cf1a08d330b64089a3c416b9479 What it says diff -r 669d7391df1a -r f5de7da165bb src/HOL/Library/List_Comprehension.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Library/List_Comprehension.thy Sat May 26 07:26:03 2007 +0200 @@ -0,0 +1,50 @@ +(* Title: HOL/Library/List_Comprehension.thy + ID: $Id$ + Author: Tobias Nipkow +*) + +header {* List Comprehension *} + +theory List_Comprehension +imports Main +begin + +text{* At the moment this theory provides only the input syntax for +list comprehension: @{text"[x. x \ xs, \]"} rather than +\verb![x| x <- xs, ...]! as in Haskell. + +The print translation from internal form to list comprehensions would +be nice. Unfortunately one cannot just turn the translations around +because in the final equality @{text p} occurs twice on the +right-hand side. Due to this restriction, the translation must be hand-coded. + +A more substantial extension would be proper theorem proving +support. For example, it would be nice if +@{text"set[f x y. x \ xs, y \ ys, P x y]"} +produced something like +@{term"{z. EX x: set xs. EX y:set ys. P x y \ z = f x y}"}. *} + +nonterminals lc_gentest + +syntax +"_listcompr" :: "'a \ idt \ 'b list \ lc_gentest \ 'a list" ("[_ . _ \ __") +"_lc_end" :: "lc_gentest" ("]") +"_lc_gen" :: "idt \ 'a list \ lc_gentest \ lc_gentest" (",_ \ __") +"_lc_test" :: "bool \ lc_gentest \ lc_gentest" (",__") + + +translations + "[e. p\xs]" => "map (%p. e) xs" + "_listcompr e p xs (_lc_gen q ys GT)" => + "concat (map (%p. _listcompr e q ys GT) xs)" + "_listcompr e p xs (_lc_test P GT)" => "_listcompr e p (filter (%p. P) xs) GT" + +(* +term "[(x,y). x \ xs, x xs, xzs]" +term "[(x,y). x \ xs, y \ ys, x xs, y \ ys, z\ zs]" +term "[x. x \ xs, x < a, x > b]" +*) + +end