src/Pure/Tools/codegen_thingol.ML
changeset 19215 03abed544f1e
parent 19214 c96ec8dd06a9
child 19253 f3ce97b5661a
equal deleted inserted replaced
19214:c96ec8dd06a9 19215:03abed544f1e
   327 
   327 
   328 fun instant_itype f =
   328 fun instant_itype f =
   329   let
   329   let
   330     fun instant (ITyVar x) = f x
   330     fun instant (ITyVar x) = f x
   331       | instant y = map_itype instant y;
   331       | instant y = map_itype instant y;
   332   in map_itype instant end;
   332   in instant end;
   333 
   333 
   334 fun is_pat (e as IConst (_, ([], _))) = true
   334 fun is_pat (e as IConst (_, ([], _))) = true
   335   | is_pat (e as IVar _) = true
   335   | is_pat (e as IVar _) = true
   336   | is_pat (e as (e1 `$ e2)) =
   336   | is_pat (e as (e1 `$ e2)) =
   337       is_pat e1 andalso is_pat e2
   337       is_pat e1 andalso is_pat e2
   798           if v = w then ty else ITyVar v;
   798           if v = w then ty else ITyVar v;
   799         fun mk_memdef (m, (sortctxt, ty)) =
   799         fun mk_memdef (m, (sortctxt, ty)) =
   800           case AList.lookup (op =) memdefs m
   800           case AList.lookup (op =) memdefs m
   801            of NONE => error ("missing definition for member " ^ quote m)
   801            of NONE => error ("missing definition for member " ^ quote m)
   802             | SOME (m', (eqs, (sortctxt', ty'))) =>
   802             | SOME (m', (eqs, (sortctxt', ty'))) =>
   803                 if eq_ityp
   803                 let
   804                   ((sortctxt |> fold (fn v_sort => AList.update (op =) v_sort) arity,
   804                   val sortctxt'' = sortctxt |> fold (fn v_sort => AList.update (op =) v_sort) arity;
   805                      instant_itype (instant (v, tyco `%% map (ITyVar o fst) arity)) ty),
   805                   val ty'' = instant_itype (instant (v, tyco `%% map (ITyVar o fst) arity)) ty;
   806                   (sortctxt', ty'))
   806                 in if eq_ityp ((sortctxt'', ty''), (sortctxt', ty'))
   807                 then (m, (m', (check_funeqs eqs, (sortctxt', ty'))))
   807                 then (m, (m', (check_funeqs eqs, (sortctxt', ty'))))
   808                 else (m, (m', (check_funeqs eqs, (sortctxt', ty'))))
   808                 else
   809 (*                 error ("inconsistent type for member definition " ^ quote m)  *)
   809                   error ("inconsistent type for member definition " ^ quote m ^ " [" ^ v ^ "]: "
       
   810                     ^ (Pretty.output o Pretty.block o Pretty.breaks) [
       
   811                       Pretty.list "(" ")" (pretty_sortcontext sortctxt''),
       
   812                       Pretty.str "|=>",
       
   813                       pretty_itype ty''
       
   814                     ] ^ " vs. " ^ (Pretty.output o Pretty.block o Pretty.breaks) [
       
   815                       Pretty.list "(" ")" (pretty_sortcontext sortctxt'),
       
   816                       Pretty.str "|=>",
       
   817                       pretty_itype ty'
       
   818                     ]
       
   819                   )
       
   820                 end
   810       in Classinst (d, map mk_memdef membrs) end
   821       in Classinst (d, map mk_memdef membrs) end
   811   | check_prep_def modl Classinstmember =
   822   | check_prep_def modl Classinstmember =
   812       error "attempted to add bare class instance member";
   823       error "attempted to add bare class instance member";
   813 
   824 
   814 fun postprocess_def (name, Datatype (_, constrs)) =
   825 fun postprocess_def (name, Datatype (_, constrs)) =