anchor.diff:  %% Programming", Aug 2012
   %% @private
   %%------------------------------------------------------------------------------
  -t0_fn([], E) ->
  -  t0(E);
  -t0_fn([{b_param,_}|_]=Params, E) ->
  +t0_fn([], E, NPs) ->
  +  t0(E, NPs);
  +t0_fn([{b_param,_}|_]=Params, E, NPs) ->
     %% Group consecutive initial base params
  -  {BPs, Ps} = lists:splitwith(fun({Type,_}) -> Type == b_param end, Params),
  -  {b_abs, [], lists:map(fun({b_param, BP}) -> BP end, BPs), t0_fn(Ps, E)};
  -t0_fn([{v_param, Param}|Ps], E) ->
  -  {v_abs, [], [Param], t0_fn(Ps, E)};
  -t0_fn([{n_param, Param}|Ps], E) ->
  -  %%------------------------------------------------------------------------------
  -  %% FIXME -- Here we need to replace Param in E with an intension
  -  %% application.  Proposition 9 in Aug 2012 semantics paper:
  +  {BPs0, Ps} = lists:splitwith(fun({Type,_}) -> Type == b_param end, Params),
  +  {_, BPs1} = lists:unzip(BPs0),
  +  {b_abs, [], BPs1, t0_fn(Ps, E, tset:difference(NPs, BPs1))};
  +t0_fn([{v_param, Param}|Ps], E, NPs) ->
  +  {v_abs, [], [Param], t0_fn(Ps, E, tset:difference(NPs, [Param]))};
  +t0_fn([{n_param, Param}|Ps], E, NamedParams) ->
  +  %%------------------------------------------------------------------------------
  +  %% Replace Param in E with an intension application.  Ref
  +  %% proposition 9 in Aug 2012 semantics paper:
     %%   [ \\ {Ei} x -> E0 ] == [ \ {Ei} x -> E0[x/↓x] ]
  -  %% FIXME -- Do the same in anonymous v_abs
  -  %%------------------------------------------------------------------------------
  -  {v_abs, [], [Param], t0_fn(Ps, E)}.
  +  %% FIXME -- Do the same in anonymous n_abs
  +  %%------------------------------------------------------------------------------
  +  {v_abs, [], [Param], t0_fn(Ps, E, tset:union(NamedParams, [Param]))}.
   
   %%------------------------------------------------------------------------------
   %% @doc Transform function call.
  
positive.code: %% {i_abs, [FrozenDimName], E}
  %% {i_apply, E}
  %%------------------------------------------------------------------------------
  transform0(E) -> t0(E).
  
  %%------------------------------------------------------------------------------
  %% Constants
  %%------------------------------------------------------------------------------
  t0(Const) when is_number(Const) orelse is_boolean(Const) ->
    Const;
  
  t0({string, Str}) ->
    {string, Str};
  
  t0({char, Char}) ->
    {char, Char};
  
  %%------------------------------------------------------------------------------
  %% Primop
  %%------------------------------------------------------------------------------
  t0({primop, F, Eis}) ->
    {primop, F, lists:map(fun t0/1, Eis)};
  
  %%------------------------------------------------------------------------------
  %% Tuple Expression
  %%------------------------------------------------------------------------------
  t0({t, E0E1is}) ->
    {t, lists:map(fun({E0,E1}) -> {t0(E0), t0(E1)} end, E0E1is)};
  
  %%------------------------------------------------------------------------------
  %% Context Perturbation
  %%------------------------------------------------------------------------------
  t0({'@', E0, E1}) ->
    {'@', t0(E0), t0(E1)};
  
  %%------------------------------------------------------------------------------
  %% Conditional
  %%------------------------------------------------------------------------------
  t0({'if', E0, E1, E2}) ->
    {'if', t0(E0), t0(E1), t0(E2)};
  
  %%------------------------------------------------------------------------------
  %% Dimensional Query
  %%------------------------------------------------------------------------------
  t0({'#', E0}) ->
    {'#', t0(E0)};
  
  %%------------------------------------------------------------------------------
  %% Base Abstraction
  %%------------------------------------------------------------------------------
  t0({b_abs, Is, Params, E}) ->
    {b_abs, [t0(I) || I <- Is], Params, t0(E)};
  
  t0({b_apply, E0, Eis}) ->
    {b_apply, t0(E0), lists:map(fun t0/1, Eis)};
  
  %%------------------------------------------------------------------------------
  %% Value Abstraction
  %%------------------------------------------------------------------------------
  t0({v_abs, Is, Params, E}) ->
    {v_abs, [t0(I) || I <- Is], Params, t0(E)};
  
  t0({v_apply, E0, Eis}) ->
    {v_apply, t0(E0), lists:map(fun t0/1, Eis)};
  
  %%------------------------------------------------------------------------------
  %% Intension Abstraction
  %%------------------------------------------------------------------------------
  t0({i_abs, Is, E}) ->
    {i_abs, [t0(I) || I <- Is], t0(E)};
  
  t0({i_apply, E}) ->
    {i_apply, t0(E)};
  
  %%------------------------------------------------------------------------------
  %% Function
  %%------------------------------------------------------------------------------
  t0({fn, Params, E}) ->
    t0_fn(Params, E);
  
  t0({fn_call, FnE, Params}) ->
    t0_fn_call(
      t0(FnE),
      lists:reverse(lists:map(fun({Type,P}) -> {Type,t0(P)} end, Params)));
  
  %%------------------------------------------------------------------------------
  %% Where
  %%------------------------------------------------------------------------------
  t0({where, E0, VDisEis}) ->
    %% We should probably signal an error when the body contains other elements..
    Vars = [{Xi, t0(Ei)} || {var,Xi,Ei} <- VDisEis],
    Dims = [{Xi, t0(Ei)} || {dim,Xi,Ei} <- VDisEis],
    t0_where(Vars, Dims, E0);
  
  %%------------------------------------------------------------------------------
  %% Identifiers
  %%------------------------------------------------------------------------------
  t0(Xi) when is_list(Xi) orelse is_atom(Xi) ->
    Xi.
  
  %%------------------------------------------------------------------------------
  %% @doc Transform function declaration.
  
negative.code:   {v_apply, t0_fn_call(FnE, Ps), [Param]};
  t0_fn_call(FnE, [{n_param, Param}|Ps]) ->
    %%------------------------------------------------------------------------------
    %% Replace the n_param with a v_param that is an intension
    %% abstraction of Param. Ref proposition 8 in Aug 2012 semantics
    %% paper:
    %%   [ E0 E1 ] == [ E0 ! (↑{} E1) ]
    %%------------------------------------------------------------------------------
    {v_apply, t0_fn_call(FnE, Ps), [{i_abs, [], Param}]}.
  
  %%------------------------------------------------------------------------------
  %% @doc Transform a where clause into wherevar / wheredims.
  %% @private
  %%------------------------------------------------------------------------------
  t0_where([], [], E0, NPs) ->
    t0(E0, NPs);
  t0_where([], Dims, E0, NPs) ->
    {wheredim, t0(E0, NPs), Dims};
  t0_where(Vars, [], E0, NPs) ->
    {wherevar, t0(E0, NPs), Vars};
  t0_where(Vars, Dims, E0, NPs) ->
    {wheredim, {wherevar, t0(E0, NPs), Vars}, Dims}.
  
  %%------------------------------------------------------------------------------
  %% Instant Tests - Please improve these
  