X-Git-Url: http://git.megacz.com/?p=coq-hetmet.git;a=blobdiff_plain;f=src%2FExtraction.v;h=dfca44c27bbf5b23e9971b09267f23ef3b8852a1;hp=57e08a3dc313cc21d3d55bf496ad795a7b31fc66;hb=f6732490f83e19174b8a8a6b487da95913d9f02d;hpb=a764632d29c79933e8c54633831e4aac0fb204f6 diff --git a/src/Extraction.v b/src/Extraction.v index 57e08a3..dfca44c 100644 --- a/src/Extraction.v +++ b/src/Extraction.v @@ -50,20 +50,15 @@ Extract Inlined Constant ascii_dec => "(==)". Extract Inductive string => "Prelude.String" [ "[]" "(:)" ]. (* adapted from ExtrOcamlString.v *) -Extract Inductive ascii => "Prelude.Char" -[ -"{- If this appears, you're using Ascii internals. Please don't -} (\ b0 b1 b2 b3 b4 b5 b6 b7 -> let f b i = if b then 1 `shiftL` i else 0 in Data.Char.chr (f b0 0 .|. f b1 1 .|. f b2 2 .|. f b3 3 .|. f b4 4 .|. f b5 5 .|. f b6 6 .|. f b7 7))" -] -"{- If this appears, you're using Ascii internals. Please don't -} (\ f c -> let n = Char.code c in let h i = (n .&. (1 `shiftL` i)) /= 0 in f (h 0) (h 1) (h 2) (h 3) (h 4) (h 5) (h 6) (h 7))". -Extract Constant zero => "'\000'". -Extract Constant one => "'\001'". -Extract Constant shift => "\ b c -> Data.Char.chr (((Char.code c) `shiftL` 1) .&. 255 .|. if b then 1 else 0)". +Extract Inductive ascii => "Prelude.Char" [ "bin2ascii" ] "bin2ascii'". +Extract Constant zero => "'\000'". +Extract Constant one => "'\001'". +Extract Constant shift => "shiftAscii". Unset Extraction Optimize. Unset Extraction AutoInline. -Axiom fail : forall {A}, string -> A. - Extract Inlined Constant fail => "Prelude.error". +Variable Prelude_error : forall {A}, string -> A. Extract Inlined Constant Prelude_error => "Prelude.error". Section core2proof. Context (ce:@CoreExpr CoreVar). @@ -72,17 +67,24 @@ Section core2proof. Definition Δ : CoercionEnv Γ := nil. - Definition φ : CoreVar->HaskTyVar Γ := - fun cv => (fun TV env => fail "unbound tyvar"). + Definition φ : TyVarResolver Γ := + fun cv => Error ("unbound tyvar: " +++ (cv:CoreVar)). (*fun tv => error ("tried to get the representative of an unbound tyvar:" +++ (getCoreVarOccString tv)).*) - Definition ψ : CoreVar->HaskCoVar nil Δ - := fun cv => fail ("tried to get the representative of an unbound covar!" (*+++ (getTypeVarOccString cv)*)). + Definition ψ : CoVarResolver Γ Δ := + fun cv => Error ("tried to get the representative of an unbound covar!" (*+++ (getTypeVarOccString cv)*)). (* We need to be able to resolve unbound exprvars, but we can be sure their types will have no * free tyvars in them *) - Definition ξ : WeakExprVar -> WeakType * list WeakTypeVar - := fun (v:WeakExprVar) => ((v:WeakType),nil). + Definition ξ (cv:CoreVar) : LeveledHaskType Γ ★ := + match coreVarToWeakVar cv with + | WExprVar wev => match weakTypeToType'' φ wev ★ with + | Error s => Prelude_error ("Error in top-level xi: " +++ s) + | OK t => t @@ nil + end + | WTypeVar _ => Prelude_error "top-level xi got a type variable" + | WCoerVar _ => Prelude_error "top-level xi got a coercion variable" + end. Definition header : string := "\documentclass[9pt]{article}"+++eol+++ @@ -102,20 +104,24 @@ Section core2proof. eol+++"\end{document}"+++ eol. + Definition handleExpr' (ce:@CoreExpr CoreVar) : ???string := + addErrorMessage ("input CoreSyn: " +++ ce) + (addErrorMessage ("input CoreType: " +++ coreTypeOfCoreExpr ce) ( + coreExprToWeakExpr ce >>= fun we => + addErrorMessage ("WeakExpr: " +++ we) + ((addErrorMessage ("CoreType of WeakExpr: " +++ coreTypeOfCoreExpr (weakExprToCoreExpr we)) + ((weakTypeOfWeakExpr we) >>= fun t => + (addErrorMessage ("WeakType: " +++ t) + ((weakTypeToType'' φ t ★) >>= fun τ => + addErrorMessage ("HaskType: " +++ τ) + ((weakExprToStrongExpr Γ Δ φ ψ ξ τ nil we) >>= fun e => + OK (eol+++"$$"+++ nd_ml_toLatex (@expr2proof _ _ _ _ _ _ e)+++"$$"+++eol) + )))))))). + Definition handleExpr (ce:@CoreExpr CoreVar) : string := - match coreExprToWeakExpr ce with - | Error s => fail ("unable to convert GHC Core expression into Coq HaskWeak expression due to:\n "+++s) - | OK me => - match weakExprToStrongExpr (*(makeClosedExpression me)*) me Γ Δ φ ψ ξ nil with - | Indexed_Error s => fail ("unable to convert HaskWeak to HaskStrong due to:\n "+++s) - | Indexed_OK τ e => match e with - | Error s => fail ("unable to convert HaskWeak to HaskStrong due to:\n "+++s) - | OK e' => - eol+++"$$"+++ - nd_ml_toLatex (@expr2proof _ _ _ _ _ _ e')+++ - "$$"+++eol - end - end + match handleExpr' ce with + | OK x => x + | Error s => Prelude_error s end. Definition handleBind (bind:@CoreBind CoreVar) : string :=