为什么odd.fst不能与过滤器功能一起使用? [英] Why does odd.fst not work with the filter function?

查看:69
本文介绍了为什么odd.fst不能与过滤器功能一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么filter odd.fst [(1,2), (2,3)]给我一个编译错误? odd.fst应该接受一个整数元组并输出一个布尔值,所以我对为什么编译器告诉我它不能匹配类型感到困惑.

Why does filter odd.fst [(1,2), (2,3)] give me a compile error? odd.fst should take in a tuple of ints and output a boolean, so I am confused as to why the compiler is telling me it can't match types.

推荐答案

出于相同的原因,2 * 3+410,而不是14.运算符优先级不关心空格:2 * 3+4解析为(2 * 3) + 4.

For the same reason that 2 * 3+4 is 10, not 14. Operator precedence does not care about spacing: 2 * 3+4 parses as (2 * 3) + 4.

类似地,

filter odd.fst [(1,2), (2,3)]

解析为

(filter odd) . (fst [(1,2), (2,3)])

无论您如何排列它.这是因为函数应用程序的优先级高于任何中缀运算符.

no matter how you space it. This is because function application has higher precedence than any infix operator.

你想要

filter (odd . fst) [(1,2), (2,3)]

相反.

这篇关于为什么odd.fst不能与过滤器功能一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆