当前位置:首页>java>函数式编程中的柯里化

函数式编程中的柯里化

  • 2026-01-20 13:16:59
函数式编程中的柯里化

作者前面的文章中有讲到函数式编程中的 “闭包” 和 “lambda演算” 概念,今天讲一下函数式编程的另一个重要概念 “柯里化”。

1.什么是柯里化?

1.1 定义

柯里化(Currying)是函数式编程中的一项核心技术,它将一个接受多个参数的函数转换为一系列只接受单一参数的函数序列。更形式化地说,对于一个定义在笛卡尔积域上的函数f: A × B → C,其柯里化形式是一个函数curry(f): A → (B → C),满足对所有a∈Ab∈Bcurry(f)(a)(b) = f(a, b)

这个定义可以扩展到任意数量的参数:函数f: A₁ × A₂ × ... × Aₙ → B的柯里化形式是curry(f): A₁ → (A₂ → (... → (Aₙ → B)...))

1.2 核心机制

柯里化的本质是参数分解函数嵌套

  1. 每次调用只接受一个参数
  2. 返回一个新函数,该函数接受下一个参数
  3. 重复此过程,直到所有参数被接收
  4. 最后一个函数执行原始计算并返回结果

这种设计利用了编程语言中的闭包(Closure)机制,每个中间函数"记住"了之前传入的参数,直到所有必要参数齐备才执行计算。

1.3 柯里化的数学基础

柯里化的理论根源在于lambda演算(Lambda Calculus)和类型理论(Type Theory)。在lambda演算中,所有函数本质上只接受一个参数。多参数函数通过函数返回函数的方式模拟实现。

在类型理论中,柯里化体现了函数空间(Function Space)的概念。类型A × B → CA → (B → C)之间存在自然同构(Natural Isomorphism)。这种同构关系是霍华德-柯里同构(Curry-Howard Isomorphism)的一部分,它建立了程序和证明之间的对应关系。

2. 历史渊源与命名由来

2.1 历史发展

"柯里化"概念最早由德国数学家莫斯·舍恩芬克尔(Moses Schönfinkel)在1924年的论文《论数理逻辑的基础》中提出。舍恩芬克尔展示了如何通过组合子逻辑消除多元函数,仅使用一元函数构建完整的逻辑系统。

美国数理逻辑学家哈斯凯尔·柯里(Haskell Brooks Curry, 1900-1982)在1930年代和1940年代扩展了舍恩芬克尔的工作,并在其1958年的专著《组合逻辑》中系统阐述了这一概念。由于柯里对此理论的推广和深入研究,这一技术最终以他的名字命名。

2.2 从理论到实践

柯里化从纯理论走向编程实践的关键节点:

1958年:Lisp语言诞生,首次在编程语言中实现类似柯里化的概念

1970年代:ML语言(MetaLanguage)正式将柯里化作为核心特性

1987年:Haskell语言设计时将柯里化作为原生特性

1990年代后期:随着函数式编程复兴,柯里化开始进入主流编程语言

2010年代:JavaScript等语言的函数式库(如Ramda、Lodash/fp)普及了柯里化技术

3. 技术实现

3.1 通用实现模式

3.1.1 基础实现

function curry(fn) {  return function curried(...args) {    if (args.length >= fn.length) {      return fn.apply(this, args);    } else {      return function(...nextArgs) {        return curried.apply(this, args.concat(nextArgs));      };    }  };}

这个实现的关键点:

  1. 检查已接收参数数量是否达到原始函数期望
  2. 若参数足够,执行原函数
  3. 否则,返回一个新函数接收更多参数
  4. 使用闭包保存已接收参数

3.1.2 支持占位符的高级实现

const _ = Symbol('placeholder');function curryAdvanced(fn) {  return function curried(...args) {    // 检查是否包含占位符    const hasPlaceholder = args.some(arg => arg === _);    // 检查是否所有必要参数已提供(忽略占位符)    const requiredArgsCount = fn.length - args.filter(arg => arg === _).length;    const providedArgsCount = args.length - args.filter(arg => arg === _).length;    if (!hasPlaceholder && args.length >= fn.length) {      return fn.apply(this, args);    }    if (providedArgsCount >= requiredArgsCount && !hasPlaceholder) {      // 替换占位符      const filledArgs = [];      let argIndex = 0;      for (let i = 0; i < fn.length; i++) {        if (args[i] === _) {          filledArgs.push(args[args.length - (fn.length - i) + argIndex]);          argIndex++;        } else {          filledArgs.push(args[i]);        }      }      return fn.apply(this, filledArgs);    }    return function(...nextArgs) {      let argIndex = 0;      const combinedArgs = args.map(arg =>         arg === _ ? nextArgs[argIndex++] : arg      );      // 添加剩余参数      while (argIndex < nextArgs.length) {        combinedArgs.push(nextArgs[argIndex++]);      }      return curried.apply(this, combinedArgs);    };  };}

3.2 语言特定实现

3.2.1 Haskell(原生支持)

-- 在Haskell中,所有函数天然就是柯里化的add :: Int -> Int -> Intadd x y = x + y-- 以下用法均为有效result1 = add 3 4    -- 7result2 = (add 34  -- 7add3 = add 3         -- 部分应用,返回 Int -> Int 函数result3 = add3 4     -- 7-- 柯里化的类型签名-- add :: Int -> (Int -> Int)-- 这表示add接受一个Int,返回一个接受Int并返回Int的函数

3.2.2 JavaScript/TypeScript实现

ES6+ 箭头函数风格:

const add = x => y => x + y;const multiply = x => y => z => x * y * z;

TypeScript泛型柯里化:

type Curry<P extends any[], R> =   <T extends any[]>(...args: T) =>     T['length'extends P['length'] ? R :    Curry<DropFirst<P, T['length']>, R>;type DropFirst<T extends any[], N extends number> =   N extends 0 ? T :  T extends [any, ...infer U] ? DropFirst<U, MinusOne<N>> :   never;function curry<P extends any[], R>(fn(...args: P) => R): Curry<P, R> {  // 实现}

3.2.3 Java实现(函数式接口)

import java.util.function.*;// 通用二元函数柯里化public static <A, B, R> Function<A, Function<B, R>> curry(BiFunction<A, B, R> f) {    return a -> b -> f.apply(a, b);}// 三元函数柯里化interface TriFunction<A, B, C, R> {    R apply(A a, B b, C c);}public static <A, B, C, R> Function<A, Function<B, Function<C, R>>> curry(TriFunction<A, B, C, R> f) {    return a -> b -> c -> f.apply(a, b, c);}// 使用示例TriFunction<IntegerIntegerIntegerInteger> sum = (a, b, c) -> a + b + c;Function<IntegerFunction<IntegerFunction<IntegerInteger>>> curriedSum = curry(sum);int result = curriedSum.apply(1).apply(2).apply(3); // 6

4. 与"部分应用"概念对比

4.1 概念对比

特性
柯里化 (Currying)
部分应用 (Partial Application)
定义
将n元函数转换为n个一元函数的链式调用
预先填充函数的部分参数,返回接受剩余参数的新函数
参数顺序
严格按定义顺序依次提供参数
可以选择性地提供任意位置的参数
返回函数
每次调用返回接受下一个参数的函数
一次调用返回接受所有剩余参数的函数
参数数量
始终处理单个参数
可以一次提供多个参数
函数结构
转换函数的内部结构
保持原函数结构,只是预设参数

4.2 代码示例对比

柯里化示例

// 原始函数function format(template, value, key) {  return template.replace(`{${key}}`, value);}// 柯里化版本const curriedFormat = template => value => key => template.replace(`{${key}}`, value);// 使用const htmlFormat = curriedFormat("<div>{value}</div>");const nameFormat = htmlFormat("John");const result = nameFormat("value"); // "<div>John</div>"// 必须按顺序提供参数const curriedResult = curriedFormat("<div>{value}</div>")("John")("value");

部分应用示例

// 部分应用函数function partial(fn, ...presetArgs) {  return function(...remainingArgs) {    const args = [];    let remainingIndex = 0;    for (let i = 0; i < fn.length; i++) {      if (i < presetArgs.length && presetArgs[i] !== undefined) {        args.push(presetArgs[i]);      } else {        args.push(remainingArgs[remainingIndex++]);      }    }    return fn(...args);  };}// 使用const formatName = partial(format, "<div>{value}</div>""John");const result = formatName("value"); // "<div>John</div>"// 也可以预设非首位参数(使用占位符)const _ = {};const formatValue = partial(format, "<div>{value}</div>", _, "value");const result2 = formatValue("Jane"); // "<div>Jane</div>"

4.3 两者关系与转换

柯里化可以用来实现部分应用,但反之则不成立:

// 用柯里化实现部分应用function partialViaCurry(fn, ...presetArgs) {  const curried = curry(fn);  return presetArgs.reduce((f, arg) => f(arg), curried);}// 但部分应用无法完全实现柯里化// 因为部分应用不保证每次只接受一个参数

在实践中,许多函数式库(如Ramda)提供的"curry"函数实际上混合了柯里化和部分应用的特性,允许灵活地提供参数。

5. 柯里化的理论深度

5.1 范畴论视角

在范畴论(Category Theory)中,柯里化是笛卡尔闭范畴(Cartesian Closed Category, CCC)的关键特性。在一个CCC中,对任意对象A、B、C,存在自然同构:

Hom(A × B, C) ≅ Hom(A, C^B)

这里,C^B表示从B到C的函数空间。这种同构正是柯里化的数学表述。

5.2 组合子逻辑基础

在组合子逻辑(Combinatory Logic)中,柯里化与基本组合子密切相关:

I组合子(Identity): I x = x

K组合子(Constant): K x y = x

S组合子(Substitution): S f g x = f x (g x)

任何可计算函数都可以用这些基本组合子表示,而柯里化是这一表达的基础。例如,加法函数可以表示为:

add = S (K S) (S (K (S (K S))) (S (K (S (K K)))) (S (K K) (S (K (S (K S))))))

这种表示虽然复杂,但展示了柯里化在理论计算模型中的基础地位。

5.3 lambda演算中的表示

在lambda演算中,柯里化是必须的,因为所有函数只能接受一个参数:

// 非柯里化形式 (伪代码)add(x, y) = x + y// lambda演算中的柯里化形式add = λx.λy.x+y

这种表示使得函数可以作为一等公民传递,支持高阶函数和函数组合。

6. 实际应用场景

6.1 配置与策略模式

// 创建可配置的验证器const createValidator = curry((field, rule, value) => {  switch(rule) {    case 'required':      return value[field] !== undefined && value[field] !== null;    case 'minLength':      return value[field] && value[field].length >= rule.value;    case 'email':      const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;      return emailRegex.test(value[field]);    default:      return true;  }});// 预设常用验证器const validateEmail = createValidator('email')('email');const validatePassword = createValidator('password')('minLength');// 使用const user = { email'test@example.com'password'weak' };console.log(validateEmail(user)); // trueconsole.log(validatePassword(8)(user)); // false (需要8字符,实际5字符)

6.2 数据处理管道

// 构建数据处理管道const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x);// 柯里化转换函数const filter = curry((predicate, array) => array.filter(predicate));const map = curry((transform, array) => array.map(transform));const sort = curry((comparator, array) => [...array].sort(comparator));// 数据转换管道const processUsers = pipe(  filter(user => user.active),  map(user => ({ ...user, fullName`${user.firstName}${user.lastName}` })),  sort((a, b) => a.fullName.localeCompare(b.fullName)));// 使用const users = [  { firstName'John'lastName'Doe'activetrue },  { firstName'Jane'lastName'Smith'activefalse },  { firstName'Alice'lastName'Johnson'activetrue }];const processed = processUsers(users);// [//   { firstName: 'Alice', lastName: 'Johnson', active: true, fullName: 'Alice Johnson' },//   { firstName: 'John', lastName: 'Doe', active: true, fullName: 'John Doe' }// ]

6.3 API客户端设计

// 构建可配置的API客户端const createApiClient = curry((config, endpoint, params) => {  const { baseUrl, headers, timeout = 5000 } = config;  return fetch(`${baseUrl}/${endpoint}`, {    method'POST',    headers: {      'Content-Type''application/json',      ...headers    },    bodyJSON.stringify(params),    timeout  }).then(response => {    if (!response.ok) {      throw new Error(`API request failed: ${response.status}`);    }    return response.json();  });});// 预设配置const githubClientConfig = {  baseUrl'https://api.github.com',  headers: { 'Authorization''token YOUR_TOKEN' }};const githubClient = createApiClient(githubClientConfig);// 预设端点const getUser = githubClient('users');const getRepo = githubClient('repos');// 使用getUser({ username'torvalds' }).then(user => console.log(user));getRepo({ owner'facebook'repo'react' }).then(repo => console.log(repo));

6.4 事件处理与UI组件

// React组件中的柯里化事件处理const Counter = ({ initialCount = 0, step = 1 }) => {  const [count, setCount] = useState(initialCount);  // 柯里化更新函数  const updateCount = curry((modifier, event) => {    setCount(prev => modifier(prev, step));  });  return (    <div>      <p>Count: {count}</p>      <buttononClick={updateCount((prev,increment) => prev + increment)}>        Increment      </button>      <buttononClick={updateCount((prev,decrement) => prev - decrement)}>        Decrement      </button>      <buttononClick={updateCount((prev,reset) => 0)}>        Reset      </button>    </div>  );};// 通用表单处理const useForm = (initialValues) => {  const [values, setValues] = useState(initialValues);  const handleChange = curry((field, event) => {    setValues(prev => ({      ...prev,      [field]: event.target.value    }));  });  return { values, handleChange };};// 使用const MyForm = () => {  const { values, handleChange } = useForm({ name''email'' });  return (    <form>      <input        name="name"         value={values.name}         onChange={handleChange('name')}       />      <input        name="email"         value={values.email}         onChange={handleChange('email')}       />    </form>  );};

7. 柯里化的性能优化

7.1 优化策略

7.1.1 缓存中间函数

function memoizedCurry(fn) {  const cache = new WeakMap();  function curried(...args) {    // 创建缓存键    const key = args.map(arg =>       typeof arg === 'function' ? arg.toString() : JSON.stringify(arg)    ).join('|');    if (args.length >= fn.length) {      return fn.apply(thisargs);    }    // 检查缓存    if (!cache.has(key)) {      cache.set(key, function(...nextArgs) {        return curried.apply(thisargs.concat(nextArgs));      });    }    return cache.get(key);  }  return curried;}

7.1.2 混合柯里化与直接调用

function smartCurry(fn) {  return function curried(...args) {    if (args.length >= fn.length) {      // 参数足够,直接执行      return fn.apply(thisargs);    } else if (args.length === 0) {      // 无参数,返回自身      return curried;    } else {      // 部分参数,返回新函数      return function(...nextArgs) {        return curried.apply(thisargs.concat(nextArgs));      };    }  };}// 使用const add = smartCurry((a, b, c) => a + b + c);add(123);      // 6 (直接执行)add(12)(3);      // 6 (部分柯里化)add(1)(23);      // 6 (混合)add(1)(2)(3);      // 6 (完全柯里化)

7.2 基准测试与分析

// 性能基准测试const iterations = 1000000;// 1. 原始函数function addRaw(a, b, c) {  return a + b + c;}// 2. 手动柯里化const addManual = a => b => c => a + b + c;// 3. 通用柯里化function curry(fn) {  return function curried(...args) {    if (args.length >= fn.length) {      return fn.apply(this, args);    }    return function(...nextArgs) {      return curried.apply(this, args.concat(nextArgs));    };  };}const addGeneric = curry((a, b, c) => a + b + c);// 测试console.time('Raw function');for (let i = 0; i < iterations; i++) {  addRaw(123);}console.timeEnd('Raw function');// 典型结果: Raw function: 15msconsole.time('Manual currying');for (let i = 0; i < iterations; i++) {  addManual(1)(2)(3);}console.timeEnd('Manual currying');// 典型结果: Manual currying: 35msconsole.time('Generic currying');for (let i = 0; i < iterations; i++) {  addGeneric(1)(2)(3);}console.timeEnd('Generic currying');// 典型结果: Generic currying: 120ms

优化建议

预先柯里化:在初始化阶段创建柯里化函数,而非运行时

选择性使用:仅对需要部分应用的函数进行柯里化

深度限制:避免深度柯里化(超过4-5层)

原生支持:在Haskell等原生支持柯里化的语言中,性能开销几乎为零

8. 柯里化的语言支持对比

8.1 原生支持(Haskell, ML系列)

-- Haskelladd :: Int -> Int -> Intadd x y = x + y-- 所有以下用法都有效add 1 2          -- 3(add 12        -- 3let add1 = add 1 in add1 2  -- 3-- 类型系统完全支持:t add           -- add :: Int -> Int -> Int:t add 1         -- add 1 :: Int -> Int

8.2 库支持(JavaScript, Python)

JavaScript (Ramda库):

const R = require('ramda');const add = R.curry((a, b, c) => a + b + c);// 灵活的参数提供方式add(123);    // 6add(12)(3);    // 6add(1)(23);    // 6add(1)(2)(3);    // 6

Python (toolz库):

ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(linefrom toolz import curry@currydef add(a, b, c):    return a + b + c使用add(1, 2, 3)     # 6add(1, 2)(3)     # 6add(1)(2, 3)     # 6add(1)(2)(3)     # 6

8.3 有限支持(Java, C#)

Java (使用函数式接口):

import java.util.function.*;// 需要为不同参数数量定义不同接口@FunctionalInterfaceinterface TriFunction<A, B, C, R> {    R apply(A a, B b, C c);}public class Currying {    public static <A, B, C, R> Function<A, Function<B, Function<C, R>>>     curry(TriFunction<A, B, C, R> f) {        return a -> b -> c -> f.apply(a, b, c);    }    public static void main(String[] args) {        TriFunction<IntegerIntegerIntegerInteger> sum = (a, b, c) -> a + b + c;        var curriedSum = curry(sum);        int result = curriedSum.apply(1).apply(2).apply(3); // 6        // 部分应用        Function<IntegerFunction<IntegerInteger>> add1And2 = curriedSum.apply(1).apply(2);        System.out.println(add1And2.apply(3)); // 6    }}

9. 高级应用

9.1 柯里化与记忆化结合

// 记忆化柯里化函数function memoizedCurry(fn) {  const cache = new Map();  function curried(...args) {    const key = JSON.stringify(args);    // 检查缓存    if (cache.has(key)) {      return cache.get(key);    }    // 如果参数足够,执行函数    if (args.length >= fn.length) {      const result = fn.apply(this, args);      cache.set(key, result);      return result;    }    // 创建新函数,合并参数    const partialFn = function(...nextArgs) {      return curried.apply(this, args.concat(nextArgs));    };    // 缓存部分应用的函数    cache.set(key, partialFn);    return partialFn;  }  return curried;}// 使用示例:记忆化的斐波那契数列const fibonacci = memoizedCurry((n) => {  console.log(`Calculating fib(${n})`);  if (n <= 1return n;  return fibonacci(n - 1) + fibonacci(n - 2);});console.log(fibonacci(10)); // 计算并缓存console.log(fibonacci(10)); // 从缓存获取

9.2 异步柯里化

// 支持Promise的柯里化function asyncCurry(fn) {  return function curried(...args) {    try {      // 检查是否有Promise参数      const hasPromise = args.some(arg => arg && typeof arg.then === 'function');      if (hasPromise) {        // 如果有Promise,等待所有Promise解决        return Promise.all(args).then(resolvedArgs =>           curried.apply(this, resolvedArgs)        );      }      if (args.length >= fn.length) {        // 参数足够,执行函数        const result = fn.apply(this, args);        // 如果结果是Promise,直接返回;否则包装为Promise        return result && typeof result.then === 'function' ?           result : Promise.resolve(result);      }      // 返回新函数,处理更多参数      return function(...nextArgs) {        return curried.apply(this, args.concat(nextArgs));      };    } catch (error) {      return Promise.reject(error);    }  };}// 使用示例const asyncAdd = asyncCurry(async (a, b, c) => {  await new Promise(resolve => setTimeout(resolve, 100));  return a + b + c;});// 链式调用asyncAdd(1)(2)(3).then(console.log); // 6// 混合Promise参数const delay = ms => new Promise(resolve => setTimeout(resolve, ms));asyncCurry((a, b) => a + b)(delay(100).then(() => 5))(10).then(console.log); // 15

9.3 柯里化与依赖注入

// 使用柯里化实现依赖注入const createService = curry((logger, database, config, serviceName) => {  return {    name: serviceName,    execute(operation, data) => {      logger.info(`[${serviceName}] Executing ${operation}`);      const result = database.execute(serviceName, operation, data);      logger.info(`[${serviceName}] Result:`, result);      return result;    },    getConfig() => config[serviceName] || {}  };});// 预设基础设施const appLogger = {  info(message, ...args) => console.log(`[LOG] ${message}`, ...args),  error(message, ...args) => console.error(`[ERROR] ${message}`, ...args)};const appDatabase = {  execute(service, operation, data) => {    // 模拟数据库操作    console.log(`[DB] ${service}.${operation}`, data);    return { successtrue, data };  }};const appConfig = {  userService: { timeout5000retries3 },  paymentService: { timeout10000retries2 }};// 创建特定服务const createAppService = createService(appLogger)(appDatabase)(appConfig);const userService = createAppService('userService');const paymentService = createAppService('paymentService');// 使用userService.execute('createUser', { name'John Doe'email'john@example.com' });paymentService.execute('processPayment', { amount100currency'USD' });

10. 局限性与解决方案

10.1 常见问题

10.1.1 调试困难

柯里化函数的调用栈可能很复杂,增加调试难度。

解决方案:使用命名函数和增强错误处理

function namedCurry(fn, name = fn.name || 'curried') {  return function curried(...args) {    try {      if (args.length >= fn.length) {        return fn.apply(this, args);      }      const partial = function(...nextArgs) {        return curried.apply(this, args.concat(nextArgs));      };      Object.defineProperty(partial, 'name', { value`${name}_${args.length}` });      return partial;    } catch (error) {      error.message = `[${name}${error.message}`;      throw error;    }  };}

10.1.2 this上下文问题

柯里化可能破坏函数的this绑定。

解决方案:显式绑定或使用箭头函数

function safeCurry(fn, context = null) {  return function curried(...args) {    if (args.length >= fn.length) {      return fn.apply(context || this, args);    }    return function(...nextArgs) {      return curried.apply(context || this, args.concat(nextArgs));    };  };}// 使用const obj = {  value10,  multiplyfunction(a, b) {    return this.value * a * b;  }};const curriedMultiply = safeCurry(obj.multiply, obj);console.log(curriedMultiply(2)(3)); // 60

10.1.3 参数顺序困境

有时理想的柯里化顺序与函数参数顺序不符。

解决方案:参数重排或使用占位符

function rearrangeCurry(fn, paramOrder) {  return function(...args) {    const reorderedArgs = paramOrder.map(index => args[index]);    return fn(...reorderedArgs);  };}// 使用占位符const _ = {};function curryWithPlaceholder(fn) {  return function curried(...args) {    const filledArgs = [];    let placeholderCount = 0;    // 计算已填充的参数    for (let i = 0; i < fn.length; i++) {      if (args[i] === _) {        placeholderCount++;      } else {        filledArgs.push(args[i]);      }    }    if (filledArgs.length === fn.length - placeholderCount && placeholderCount === 0) {      return fn(...filledArgs);    }    return function(...nextArgs) {      let argIndex = 0;      const combinedArgs = args.map(arg =>         arg === _ ? nextArgs[argIndex++] : arg      );      // 添加额外参数      while (argIndex < nextArgs.length) {        combinedArgs.push(nextArgs[argIndex++]);      }      return curried(...combinedArgs);    };  };}// 示例:改变参数顺序const formatTemplate = curryWithPlaceholder((value, key, template) => {  return template.replace(`{${key}}`, value);});const htmlFormatter = formatTemplate(_, 'value''<div>{value}</div>');console.log(htmlFormatter('John')); // <div>John</div>

11. 现代框架中的应用

11.1 React与函数组件

// 使用柯里化创建可配置的Hookconst useLocalStorage = curry((keyPrefix, defaultValue, specificKey) => {  const [storedValue, setStoredValue] = useState(() => {    if (typeof window === 'undefined') {      return defaultValue;    }    try {      const item = window.localStorage.getItem(`${keyPrefix}_${specificKey}`);      return item ? JSON.parse(item) : defaultValue;    } catch (error) {      console.error(error);      return defaultValue;    }  });  const setValue = useCallback((value) => {    try {      const valueToStore = value instanceof Function ? value(storedValue) : value;      setStoredValue(valueToStore);      window.localStorage.setItem(`${keyPrefix}_${specificKey}`JSON.stringify(valueToStore));    } catch (error) {      console.error(error);    }  }, [keyPrefix, specificKey, storedValue]);  return [storedValue, setValue];});// 预设应用级别的存储const useAppStorage = useLocalStorage('myapp');// 使用function UserProfile() {  const [user, setUser] = useAppStorage({ name''email'' }, 'user');  const [theme, setTheme] = useAppStorage('light''theme');  // ...}

11.2 Redux中间件

// Redux中间件使用柯里化const logger = store => next => action => {  console.log('dispatching', action);  const result = next(action);  console.log('next state', store.getState());  return result;};// 异步中间件const apiMiddleware = ({ dispatch, getState }) => next => async action => {  if (typeof action === 'function') {    return action(dispatch, getState);  }  if (action.api) {    try {      const { endpoint, method = 'GET', body, onSuccess, onError } = action.api;      dispatch({ type`${action.type}_PENDING` });      const response = await fetch(endpoint, {        method,        headers: { 'Content-Type''application/json' },        body: body ? JSON.stringify(body) : undefined      });      if (!response.ok) {        throw new Error(`API request failed with status ${response.status}`);      }      const data = await response.json();      dispatch({ type`${action.type}_SUCCESS`payload: data });      if (onSuccess) {        onSuccess(dispatch, data);      }      return data;    } catch (error) {      dispatch({ type`${action.type}_FAILURE`error: error.message });      if (onError) {        onError(dispatch, error);      }      throw error;    }  }  return next(action);};

12. 未来发展方向

12.1 语言级支持增强

JavaScript/TypeScript: 管道操作符(|>)提案将增强函数组合能力

// 提案中的用法const result = input  |> double  |> add(5)  |> toString;

Java: 通过Project Valhalla引入值类型,优化函数对象内存占用

Python: 模式匹配与增强的类型系统将支持更安全的柯里化

12.2 编译器优化

现代编译器正在优化柯里化调用:

GHC (Haskell): 专业化和内联消除柯里化开销

V8 (JavaScript): 内联缓存和类型反馈优化高阶函数

JIT编译器: 动态重编译频繁调用的柯里化链

12.3 跨领域应用

机器学习: 可微分编程利用柯里化构建动态计算图

# 伪代码:可微分柯里化@differentiabledef layer(weights, activation, input):    return activation(matmul(weights, input))linear_layer = layer(weights_matrix)  # 预设权重relu_layer = linear_layer(relu)       # 预设激活函数output = relu_layer(input_data)       # 应用输入

量子计算: 量子函数组合利用柯里化构建量子门序列

分布式系统: 服务组合通过柯里化配置中间件链

13.实践建议

13.1 逐步实践建议

  • 从二元函数柯里化开始

const add = x => y => x + y;const multiply = x => y => x * y;
  • 实现通用柯里化函数

function curry(fn) {  return function curried(...args) {    if (args.length >= fn.lengthreturn fn(...args);    return (...nextArgs) => curried(...args, ...nextArgs);  };}
  • 在真实项目中找一个适合柯里化的场景

  • 结合其他函数式技术

13.2 常见误区与避免方法

  • 过度柯里化: 不是所有函数都需要柯里化,仅当需要部分应用时使用

  • 忽略性能: 在性能关键路径避免深度柯里化

  • 破坏API一致性: 混合柯里化和非柯里化函数可能使API不一致

  • 忽视可读性: 过度使用点自由风格可能降低代码可读性

14. 总结

柯里化不仅是技术技巧,更代表了一种计算思维的转变:

  • 分解复杂性: 将复杂操作分解为简单、可组合的单元

  • 关注点分离: 将配置与执行、策略与实现分离

  • 抽象提升: 从具体值操作上升到函数操作

  • 组合优于继承: 通过函数组合而非类继承构建系统

在软件设计中,柯里化体现了"做一件事并做好"(Do One Thing Well)的Unix哲学,同时支持"小块构建大物"(Small Pieces Loosely Joined)的系统构建原则。

💡 "一个程序语言的威力不在于它能做什么,而在于它鼓励我们如何思考。" 柯里化正是这样一种思维工具,它扩展了我们的表达能力,丰富了我们的设计词汇,最终让我们能够构建更加优雅、强大的软件系统。

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-02-09 01:49:15 HTTP/2.0 GET : https://f.mffb.com.cn/a/462728.html
  2. 运行时间 : 0.269490s [ 吞吐率:3.71req/s ] 内存消耗:4,770.70kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=4df6f62ea38133ab28429d9e46609957
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000967s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.001478s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000724s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000725s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.001544s ]
  6. SELECT * FROM `set` [ RunTime:0.000609s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.001462s ]
  8. SELECT * FROM `article` WHERE `id` = 462728 LIMIT 1 [ RunTime:0.013896s ]
  9. UPDATE `article` SET `lasttime` = 1770572955 WHERE `id` = 462728 [ RunTime:0.018029s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 65 LIMIT 1 [ RunTime:0.002912s ]
  11. SELECT * FROM `article` WHERE `id` < 462728 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.001221s ]
  12. SELECT * FROM `article` WHERE `id` > 462728 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.010417s ]
  13. SELECT * FROM `article` WHERE `id` < 462728 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.042184s ]
  14. SELECT * FROM `article` WHERE `id` < 462728 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.010936s ]
  15. SELECT * FROM `article` WHERE `id` < 462728 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.003273s ]
0.273300s