Haskell:映射功能应用程序 [英] Haskell: mapping function application

查看:116
本文介绍了Haskell:映射功能应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Haskell中进行的部分计算会生成将Float映射到Float的函数列表.我想对所有这些函数应用一个参数,就像这样:

Part of some computation I am doing in Haskell results in a list of functions that map Float to Float. I'd like to apply a single argument to all these functions, like so:

-- x :: Float
-- functions :: [Float -> Float]
map (\f -> f x) functions

有没有一种方法,而无需使用一次性Lambda函数呢?我已经搜索 Hoogle ,我认为签名应该是([a -> b] -> a -> [b])没有运气.

Is there a way to do this without making use of a throw-away lambda function? I've searched Hoogle for what I think the signature should be ([a -> b] -> a -> [b]) with no luck.

推荐答案

您可以使用$运算符,它只是函数应用程序:

You can use the $ operator, which is just function application:

map ($ x) functions

(这前提是x在表达式的范围内.)

(This presupposes that x is in scope for the expression.)

Hoogle只能找到函数,不能找到任意表达式.由于使用的是map,因此您想搜索类似(a -> b) -> a -> b的函数,而不要搜索任何涉及列表的函数.给定一个正常函数,将其传递给map使其作用于列表.

Hoogle can only find functions, not arbitrary expressions. Since you're using map, you wanted to search for a function like (a -> b) -> a -> b rather than anything involving lists. Given a normal function, passing it to map makes it act on lists.

这篇关于Haskell:映射功能应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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