src/Tools/Haskell/Haskell.thy
changeset 74188 ea10e06adede
parent 74187 6109a9105a7a
child 74194 ffe24c7da1c6
equal deleted inserted replaced
74187:6109a9105a7a 74188:ea10e06adede
  2209 {-# LANGUAGE OverloadedStrings #-}
  2209 {-# LANGUAGE OverloadedStrings #-}
  2210 
  2210 
  2211 module Isabelle.Term (
  2211 module Isabelle.Term (
  2212   Indexname, Sort, Typ(..), Term(..),
  2212   Indexname, Sort, Typ(..), Term(..),
  2213   Free, lambda, declare_frees, incr_boundvars, subst_bound, dest_abs, strip_abs,
  2213   Free, lambda, declare_frees, incr_boundvars, subst_bound, dest_abs, strip_abs,
  2214   type_op0, type_op1, op0, op1, op2, typed_op2, binder,
  2214   type_op0, type_op1, op0, op1, op2, typed_op1, typed_op2, binder,
  2215   dummyS, dummyT, is_dummyT, propT, is_propT, (-->), dest_funT, (--->),
  2215   dummyS, dummyT, is_dummyT, propT, is_propT, (-->), dest_funT, (--->),
  2216   aconv, list_comb, strip_comb, head_of
  2216   aconv, list_comb, strip_comb, head_of
  2217 )
  2217 )
  2218 where
  2218 where
  2219 
  2219 
  2343   where
  2343   where
  2344     mk t u = App (App (Const (name, []), t), u)
  2344     mk t u = App (App (Const (name, []), t), u)
  2345     dest (App (App (Const (c, _), t), u)) | c == name = Just (t, u)
  2345     dest (App (App (Const (c, _), t), u)) | c == name = Just (t, u)
  2346     dest _ = Nothing
  2346     dest _ = Nothing
  2347 
  2347 
       
  2348 typed_op1 :: Name -> (Typ -> Term -> Term, Term -> Maybe (Typ, Term))
       
  2349 typed_op1 name = (mk, dest)
       
  2350   where
       
  2351     mk ty t = App (Const (name, [ty]), t)
       
  2352     dest (App (Const (c, [ty]), t)) | c == name = Just (ty, t)
       
  2353     dest _ = Nothing
       
  2354 
  2348 typed_op2 :: Name -> (Typ -> Term -> Term -> Term, Term -> Maybe (Typ, Term, Term))
  2355 typed_op2 :: Name -> (Typ -> Term -> Term -> Term, Term -> Maybe (Typ, Term, Term))
  2349 typed_op2 name = (mk, dest)
  2356 typed_op2 name = (mk, dest)
  2350   where
  2357   where
  2351     mk ty t u = App (App (Const (name, [ty]), t), u)
  2358     mk ty t u = App (App (Const (name, [ty]), t), u)
  2352     dest (App (App (Const (c, [ty]), t), u)) | c == name = Just (ty, t, u)
  2359     dest (App (App (Const (c, [ty]), t), u)) | c == name = Just (ty, t, u)
  2412 -}
  2419 -}
  2413 
  2420 
  2414 {-# LANGUAGE OverloadedStrings #-}
  2421 {-# LANGUAGE OverloadedStrings #-}
  2415 
  2422 
  2416 module Isabelle.Pure (
  2423 module Isabelle.Pure (
  2417   mk_forall, dest_forall, mk_equals, dest_equals, mk_implies, dest_implies
  2424   mk_forall_op, dest_forall_op, mk_forall, dest_forall,
       
  2425   mk_equals, dest_equals, mk_implies, dest_implies
  2418 )
  2426 )
  2419 where
  2427 where
  2420 
  2428 
  2421 import qualified Isabelle.Name as Name
  2429 import qualified Isabelle.Name as Name
  2422 import Isabelle.Term
  2430 import Isabelle.Term
       
  2431 
       
  2432 mk_forall_op :: Typ -> Term -> Term; dest_forall_op :: Term -> Maybe (Typ, Term)
       
  2433 (mk_forall_op, dest_forall_op) = typed_op1 \<open>\<^const_name>\<open>Pure.all\<close>\<close>
  2423 
  2434 
  2424 mk_forall :: Free -> Term -> Term; dest_forall :: Name.Context -> Term -> Maybe (Free, Term)
  2435 mk_forall :: Free -> Term -> Term; dest_forall :: Name.Context -> Term -> Maybe (Free, Term)
  2425 (mk_forall, dest_forall) = binder \<open>\<^const_name>\<open>Pure.all\<close>\<close>
  2436 (mk_forall, dest_forall) = binder \<open>\<^const_name>\<open>Pure.all\<close>\<close>
  2426 
  2437 
  2427 mk_equals :: Typ -> Term -> Term -> Term; dest_equals :: Term -> Maybe (Typ, Term, Term)
  2438 mk_equals :: Typ -> Term -> Term -> Term; dest_equals :: Term -> Maybe (Typ, Term, Term)
  2447   boolT, is_boolT, mk_trueprop, dest_trueprop,
  2458   boolT, is_boolT, mk_trueprop, dest_trueprop,
  2448   mk_setT, dest_setT, mk_mem, dest_mem,
  2459   mk_setT, dest_setT, mk_mem, dest_mem,
  2449   mk_eq, dest_eq, true, is_true, false, is_false,
  2460   mk_eq, dest_eq, true, is_true, false, is_false,
  2450   mk_not, dest_not, mk_conj, dest_conj, mk_disj, dest_disj,
  2461   mk_not, dest_not, mk_conj, dest_conj, mk_disj, dest_disj,
  2451   mk_imp, dest_imp, mk_iff, dest_iff,
  2462   mk_imp, dest_imp, mk_iff, dest_iff,
       
  2463   mk_all_op, dest_all_op, mk_ex_op, dest_ex_op,
  2452   mk_all, dest_all, mk_ex, dest_ex
  2464   mk_all, dest_all, mk_ex, dest_ex
  2453 )
  2465 )
  2454 where
  2466 where
  2455 
  2467 
  2456 import qualified Isabelle.Name as Name
  2468 import qualified Isabelle.Name as Name
  2496 dest_iff :: Term -> Maybe (Term, Term)
  2508 dest_iff :: Term -> Maybe (Term, Term)
  2497 dest_iff tm =
  2509 dest_iff tm =
  2498   case dest_eq tm of
  2510   case dest_eq tm of
  2499     Just (ty, t, u) | ty == boolT -> Just (t, u)
  2511     Just (ty, t, u) | ty == boolT -> Just (t, u)
  2500     _ -> Nothing
  2512     _ -> Nothing
       
  2513 
       
  2514 mk_all_op :: Typ -> Term -> Term; dest_all_op :: Term -> Maybe (Typ, Term)
       
  2515 (mk_all_op, dest_all_op) = typed_op1 \<open>\<^const_name>\<open>All\<close>\<close>
       
  2516 
       
  2517 mk_ex_op :: Typ -> Term -> Term; dest_ex_op :: Term -> Maybe (Typ, Term)
       
  2518 (mk_ex_op, dest_ex_op) = typed_op1 \<open>\<^const_name>\<open>Ex\<close>\<close>
  2501 
  2519 
  2502 mk_all :: Free -> Term -> Term; dest_all :: Name.Context -> Term -> Maybe (Free, Term)
  2520 mk_all :: Free -> Term -> Term; dest_all :: Name.Context -> Term -> Maybe (Free, Term)
  2503 (mk_all, dest_all) = binder \<open>\<^const_name>\<open>All\<close>\<close>
  2521 (mk_all, dest_all) = binder \<open>\<^const_name>\<open>All\<close>\<close>
  2504 
  2522 
  2505 mk_ex :: Free -> Term -> Term; dest_ex :: Name.Context -> Term -> Maybe (Free, Term)
  2523 mk_ex :: Free -> Term -> Term; dest_ex :: Name.Context -> Term -> Maybe (Free, Term)