anchor.diff:    | (inputs, body) -> Some(inputs, body)
   
   let (|LetN|_|) (e: Expr): ((Var * Expr) List * Expr) Option = 
  -  let rec letNExtract exp statements = match exp with 
  +  let rec letNExtract exp statements = 
  +    match exp with 
       | Patterns.Let(x, e1, e2) -> letNExtract e2 (List.append statements [(x, e1)]) 
       | _ -> (statements, exp)
     match letNExtract e [] with 
  
positive.code:   let (rhs, funs, includesLhs) = 
      match e with 
      | Patterns.NewArray(tp, elems) -> 
        let args = (String.concat "\n\t" (List.mapi (fun index elem -> sprintf "%s->arr[%d] = %s;" var.Name index (ccodegen elem)) elems))
        let arrTp = ccodegenType (tp.MakeArrayType()) 
        let elemTp = (ccodegenType tp)
        let rhs = sprintf "(%s)malloc(sizeof(int) * 2);\n\t%s->length=%d;\n\t%s->arr = (%s*)malloc(sizeof(%s) * %d);\n\t%s" arrTp var.Name (List.length elems)  var.Name elemTp elemTp (List.length elems) args
        (rhs, [], false)
      | MakeClosure(envVar, lamBody, fields) ->
        let lambdaName = newVar "lambda"
        let id = variable_counter
        let envName = sprintf "env_t_%d" id
        let fieldsDeclList = List.map (fun (tp, v) -> ccodegenType(tp) + " " + v) fields
        let fieldsStructDecl = match fieldsDeclList with 
        | [] -> (ccodegenType (typeof<AnyNumeric>)) + " dummy_variable;" (* This is because C does not accept structs without any member *)
        | _ ->(String.concat "\n\t" (List.map (fun x -> x + ";") fieldsDeclList))
        let envStruct = sprintf "typedef struct %s {\n\t%s\n} %s;" envName fieldsStructDecl envName
        let fieldsDecl = String.concat "," fieldsDeclList
        let fieldsInit = String.concat "\n\t" (List.map (fun (_, v) -> sprintf "env->%s = %s;" v v) fields)
        let makeEnvDef = sprintf "%s* make_%s(%s) {\n\t%s* env = (%s*)malloc(sizeof(%s));\n\t%s\n\treturn env;\n}" envName envName fieldsDecl envName envName envName fieldsInit
        let makeEnvInvoke = sprintf "make_%s(%s)" envName (String.concat "," (List.map (fun (_, v) -> v) fields))
        (sprintf "make_closure(%s, %s)" lambdaName makeEnvInvoke, [envStruct; makeEnvDef; ccodegenFunction (Expr.Lambda(envVar, lamBody)) lambdaName true], false)
      | Patterns.IfThenElse(cond, e1, e2) ->
        let ccodegenStatements exp = 
          let (stmts, res) = match exp with 
          | LetN(stmts, res) -> stmts, res
          | _ -> [], exp
          let (statementsCodeList, closuresList) = List.unzip (List.map ccodegenStatement stmts)
          let statementsCode = (String.concat "\n\t\t" statementsCodeList)
          (sprintf "%s\n\t\t%s = %s;" statementsCode (var.Name) (ccodegen res), List.concat closuresList)
  
negative.code: 
  let (|MakeClosure|_|) (e: Expr): (Var * Expr * ((System.Type * string) List)) Option = 
    match e with 
    | Patterns.Call (None, op, [Patterns.Lambda(envVar, body); Patterns.Call (None, opEnv, list)]) when 
        op.Name = "makeClosure" && opEnv.Name = "makeEnv" -> 
      let envList = 
        let rec extractElems l = 
          match l with
          (* The pattern `Patterns.Call (_, _, [e])` performs an additional level of specialization.
             This specialization results in not using a union type for the variables in the enviroment 
             of a closure. *)
          | [ Patterns.NewUnionCase(_, 
               [ Patterns.NewTuple([Patterns.Value(v, _); 
                                    Patterns.Call (_, _, [e])]); tl]) ] ->
            (e.Type, v.ToString()) :: extractElems([tl])
          | _ -> []
        extractElems list
  