anchor.diff:      end.
   
   do_type_ann_args_1(ParTypes, MappedArgs, Args) ->
  -    lists:map(fun({T,A}) ->
  -		      ?debug("AT:\n~p\n", [{A, T}]),
  -		      case T of 
  -			  any ->
  -			      A;
  -			  _  when is_function(T)->
  -			      ?debug("MappedArgS:\n~p\n",[MappedArgs]),
  -			      ?debug("TMappedArgs:\n~p\n", [T(MappedArgs)]),
  -			      add_type_info({type, T(MappedArgs)}, A);
  -			  {f_atom, [M, F, Arity]} ->
  -			      ?debug("T:\n~p\n", [T]),
  -			      M1 = case is_function(M) of
  -				       true -> M(MappedArgs);
  -				       _ -> M
  -				   end,
  -			      F1 = case is_function(F) of
  +    ZippedParTypeArgs = lists:zip(ParTypes, Args),
  +    lists:map(fun ({ParType, Arg}) ->
  +		      ?debug("AT:\n~p\n", [{Arg, ParType}]),
  +		      case ParType of
  +			any ->
  +			    Arg;
  +			_ when is_function(ParType) ->
  +			    ?debug("MappedArgS:\n~p\n", [MappedArgs]),
  +			    ?debug("TMappedArgs:\n~p\n", [ParType(MappedArgs)]),
  +			    add_type_info({type, ParType(MappedArgs)}, Arg);
  +			{f_atom, [M, F, Arity]} ->
  +			    ?debug("T:\n~p\n", [ParType]),
  +			    M1 = case is_function(M) of
  +				   true -> M(MappedArgs);
  +				   _ -> M
  +				 end,
  +			    F1 = case is_function(F) of
  +				   true ->
  +				       F(MappedArgs);
  +				   _ -> M
  +				 end,
  +			    Arity1 = case is_function(Arity) of
   				       true ->
  -					   F(MappedArgs);
  -				       _ ->M
  -				   end,
  -			      Arity1 = case is_function(Arity) of
  -					  true ->
  -					    Arity(MappedArgs);
  -					  _ -> Arity
  -				      end,
  -			      ?debug("M1:\n~p\n", [M1]),
  -                              ?debug("F1:\n~p\n", [F1]),
  -			      ?debug("Arity1:\n~p\n", [Arity1]),
  -			      add_type_info({type, {f_atom, [M1, F1, Arity1]}}, A);
  -			  _ ->
  -			      ?debug("T:\n~p\n", [T]),
  -			      ?debug("A:\n~p\n", [A]),
  -			      add_type_info({type, T}, A)
  +					   Arity(MappedArgs);
  +				       _ -> Arity
  +				     end,
  +			    ?debug("M1:\n~p\n", [M1]),
  +			    ?debug("F1:\n~p\n", [F1]),
  +			    ?debug("Arity1:\n~p\n", [Arity1]),
  +			    add_type_info({type, {f_atom, [M1, F1, Arity1]}}, Arg);
  +			_ ->
  +			    ?debug("T:\n~p\n", [ParType]),
  +			    ?debug("A:\n~p\n", [Arg]),
  +			    add_type_info({type, ParType}, Arg)
   		      end
  -	      end, lists:zip(ParTypes, Args)).
  -
  -
  -type(erlang, apply, 3) ->
  -    {[m_atom, fun(Args)->
  -		      case Args of 
  -			  [A1, A2, A3] ->
  -			      {f_atom, [try_eval(A1, fun is_atom/1), try_eval(A2, fun is_atom/1),
  -					try_eval_length(A3)]};
  -			  _ -> {f_atom, ['_','_','_']}
  -		      end
  -	      end, any], any};
  -type(_, _, _) ->
  -    none.
  -
  -
  -try_eval(Expr,Cond) when is_function(Expr) ->
  -    fun(X)->try_eval(Expr(X), Cond) end;
  -try_eval(Expr, Cond) ->
  -    
  -    E1 = refac_syntax:revert(Expr),
  -    ?debug("E1:\n~p\n", [E1]),
  -    try erl_eval:expr(E1, []) of 
  -	{value, V, _} ->
  -	    ?debug("V:\n~p\n", [V]),
  -	    case Cond(V) of 
  -		true -> V;
  -		_ -> '_'
  -	    end
  -    catch 
  -	_E1:_E2 -> 
  -	    ?debug("Expr:\n~p\n", [Expr]),
  -	    As = refac_syntax:get_ann(Expr),
  -	    case lists:keysearch(value, 1, As) of 
  -		{value, {value, {{_,V}, _DefPos}}} ->
  -		    case Cond(V) of 
  -			true ->
  -			    ?debug("V:\n~p\n",[V]),   
  -			    V;
  -			_ -> '_'
  -		    end;
  -		_ -> '_'
  -	    end	    
  -    end.
  -
  -try_eval_length(Expr) when is_function(Expr) ->
  -    fun(X)->try_eval_length(Expr(X)) end; 
  -try_eval_length(Expr) ->
  -    E = refac_syntax:set_pos(refac_syntax:application(
  -				refac_syntax:set_pos(
  -				  refac_syntax:atom(length),{1,1}), [Expr]), {1,1}),
  -    E1 = refac_syntax:revert(E),
  -    try erl_eval:expr(E1, []) of 
  -	{value, V, _} ->
  -	    V
  -    catch 
  -	_E1:_E2 -> 
  -	    As = refac_syntax:get_ann(Expr),
  -	    ?debug("As:\n~p\n", [As]),
  -	    case lists:keysearch(value, 1, As) of 
  -		{value, {value, {{list, V}, _DefPos}}} ->
  -		  V;
  -		_ -> 
  -		    ?debug("Expr:\n~p\n", [Expr]),
  -		    case refac_syntax:type(Expr) of 
  -			list -> refac_syntax:list_length(Expr);
  -			_ -> '_'
  -		    end
  -	    end	    
  -    end.
  -    
  +	      end, ZippedParTypeArgs).
  +
   
   add_type_info({type, Type}, Node) ->
       As =refac_syntax:get_ann(Node),
       Ps = [{Pos, {type, Type}}|| {value, {_,  Pos}} <- As],
       Ps1 =lists:append([[{Pos, {type, Type}}|| Pos<-Poss] ||{def, Poss} <-As]),
  -    ?debug("Ps:\n~p\n", [Ps]),
  -    ?debug("Ps1:\n~p\n", [Ps1]),
       add_to_type_env(Ps++Ps1),
  -    Node1 = refac_syntax:add_ann({type, Type}, Node),
  -    ?debug("Node1:\n~p\n", [Node1]),
  -    Node1.
  +    refac_syntax:add_ann({type, Type}, Node).
  +   
  +
  +map_args(Pats, ActualArgs) ->
  +    Fun = fun (ActualArg) ->
  +		  case refac_syntax:type(ActualArg) of
  +		      literal ->
  +			  ActualArg;
  +		      variable ->
  +			  As = refac_syntax:get_ann(ActualArg),
  +			  case lists:keysearch(def, 1, As) of
  +			      {value, {def, DefinePos}} ->
  +				  {Ps1, _Ps2} = lists:splitwith(
  +					      fun (P) -> case refac_syntax:type(P) of
  +							     variable ->
  +								 As1 = refac_syntax:get_ann(P),
  +								 case lists:keysearch(def, 1, As1) of
  +								     {value, {def, DefinePos}} ->
  +									 false;
  +								     _ -> true
  +								 end;
  +							     _ -> true
  +							 end
  +					      end, Pats),
  +				  case length(Ps1) == length(Pats) of
  +				      true ->
  +					  ActualArg;
  +				      _ ->
  +					  ?debug("nth:\n~p\n", [length(Ps1) + 1]),
  +					  fun (P) -> lists:nth(length(Ps1) + 1, P) end
  +				  end;
  +			      _ ->
  +				  ActualArg
  +			  end;
  +		      _ -> ActualArg
  +		  end
  +	  end,
  +    Res = lists:map(Fun, ActualArgs),
  +    ?debug("Res:\n~p\n", [Res]),
  +    Res.
  +
  +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	
  +
  +get_pat_type(P, TypeInfo) ->
  +    case refac_syntax:type(P) of
  +	variable ->
  +	    As = refac_syntax:get_ann(P),
  +	    case lists:keysearch(def, 1, As) of
  +		{value, {def, [DefinePos]}} ->
  +		    case lists:keysearch(DefinePos, 1, TypeInfo) of
  +			{value, {DefinePos, {type, T}}} ->
  +			    T;
  +			_ -> any
  +		    end;
  +		_ -> any
  +	    end;
  +	_ -> any
  +    end.
  +
  +
  +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  +%%                                                                       %%
  +%%                 Propagate Type Information to Atoms                   %%
  +%%                                                                       %%
  +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  +prop_type_info(AnnAST, TypeEnv) ->  
  +    refac_util:stop_tdTP(fun do_prop_type_info/2, AnnAST, TypeEnv).
  +  
  +do_prop_type_info(Node, TypeEnv) ->
  +    case refac_syntax:type(Node) of 
  +	atom ->
  +	    Pos = refac_syntax:get_pos(Node),
  +	    Ts =lists:usort([Type||{P, Type} <-TypeEnv, P==Pos]),
  +	    case Ts of
  +		[] ->
  +		    {Node, true};
  +		_ ->
  +		    Type = element(2, lists:unzip(Ts)),
  +		    Node1 = refac_syntax:add_ann({type, Type}, Node),
  +		    refac_io:format("AtomNodeWithTypeInfo:\n~p\n", [Node1]),
  +		    {Node1, true}
  +	    end;	    
  +	_ -> {Node, false}
  +    end.
  +  
  +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  +%%                                                                       %%
  +%%                 Type Info Server                                      %%
  +%%                                                                       %%
  +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   
   start_type_env_process() ->
       Pid = spawn_link(fun() -> type_env_loop([]) end), 
  
positive.code: 	{From, get_all} ->
  	    From ! {type_env, Env},
  	    type_env_loop(Env);
  	init ->
  	    type_env_loop([]);
  	stop ->
  	   %% ?debug("process stoped.\n"),
  	    ok
      end.
  
  prop_type_info(AnnAST, TypeEnv) ->  
      refac_util:stop_tdTP(fun do_prop_type_info/2, AnnAST, TypeEnv).
    
  do_prop_type_info(Node, TypeEnv) ->
      case refac_syntax:type(Node) of 
  	atom ->
  	    Pos = refac_syntax:get_pos(Node),
  	    Ts =lists:usort([Type||{P, Type} <-TypeEnv, P==Pos]),
  	    case Ts of
  		[] ->
  		    {Node, true};
  		_ ->
  		    Node1 = lists:foldl(fun(T, N)->
  						refac_syntax:add_ann(T, N)
  					end, Node, Ts),
  		    {Node1, true}
  	    end;	    
  	_ -> {Node, false}
      end.
    
  map_args(Pats, ActualArgs)->
      Fun= fun(Expr) ->
  		 case refac_syntax:type(Expr) of 
  		     literal -> 
  			 Expr;
  		     variable ->
  			 As = refac_syntax:get_ann(Expr),
  			 case lists:keysearch(def, 1, As) of
  			     {value, {def, DefinePos}} ->
  				 {Ps1, _Ps2} = lists:splitwith(
  						 fun(P) -> case refac_syntax:type(P) of
  							       variable ->
  								   As1 =refac_syntax:get_ann(P),
  								   case lists:keysearch(def,1,As1) of
  								       {value, {def, DefinePos}} ->
  									   false;
  								       _ -> true
  								   end;
  							       _ -> true
  							   end
  						 end, Pats),
  				 case length(Ps1) == length(Pats) of 
  				     true ->
  					 Expr;
  				     _ -> 
  					 ?debug("nth:\n~p\n", [length(Ps1)+1]),
  					 fun(P) -> lists:nth(length(Ps1)+1, P) end
  				 end;
  			     _ ->
  				 Expr
  			 end;
  		     _ ->  Expr
  		 end
  	 end,
      Res = lists:map(Fun, ActualArgs),
      ?debug("Res:\n~p\n", [Res]),
      Res.
  	
  
  %% sort_funs(File) ->
  %%      CallGraph = wrangler_callgraph_server:get_callgraph([File]),
  %%      CallGraph.
       %% TrimmedSccs = trim_scc(CallGraph#callgraph.scc_order, CallGraph#callgraph.callercallee, [], []),
       %% lists:append(TrimmedSccs).
  
  %% trim_scc([], _CallerCallee, _PFunAcc, Acc) -> lists:reverse(Acc);
  %% trim_scc([Scc | Sccs], CallerCallee, PFunAcc, Acc) ->
  %%     SccFuns = lists:map(fun ({Fun, _FunDef}) -> Fun end, Scc),
  %%     IsProcessScc = lists:any(fun ({_Fun, FunDef}) -> is_process_related_fun(FunDef) end, Scc),
  %%     CalledFuns = lists:usort(lists:flatmap(fun (Fun) ->
  %% 						   case lists:keysearch(Fun, 1, CallerCallee) of
  %% 						     {value, {Fun, Called}} -> Called;
  %% 						     _ -> []
  %% 						   end
  %% 					   end,
  %% 					   SccFuns)),
  %%     PFunsCalled = length(lists:subtract(CalledFuns, PFunAcc)) < length(CalledFuns),
  %%     case IsProcessScc orelse PFunsCalled of
  %%       true -> trim_scc(Sccs, CallerCallee, SccFuns ++ PFunAcc, [Scc | Acc]);
  %%       _ -> trim_scc(Sccs, CallerCallee, PFunAcc, Acc)
  %%     end.
  
  %% type(erlang, apply, 3) ->
  %%     {[m_atom, f_atom, any], any};
  %% type(erlang, unregister, 1) ->
  %%     {[p_atom], any};
  %% type(erlang, whereis, 1) ->
  %%     {[p_atom], any};
  %% type(_M,_F, _A)->
  %%     none.
  
negative.code: 
  -export([try_eval/2]).
  
  -compile(export_all).
  
  %%-define(DEBUG, true).
  
  -ifdef(DEBUG).
  -define(debug(__String, __Args), ?wrangler_io(__String, __Args)).
  