如何将值应用于函数列表 [英] How to apply a value to a list of functions

查看:90
本文介绍了如何将值应用于函数列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想达到的是:

  apply :: a  - > [a  - > b]  - > [b] 

这是一种与地图相反的情况:

  map ::(a  - > b) - > [a]  - > [b] 

我试过Hoogle,但无济于事。任何人都可以在Haskell中提供一个干净的方式来做这件事吗?

解决方案

  apply :: a - > [a  - > b]  - > [b] 
apply a = map($ a)

这是一种简洁的方式说:

  apply a = map(\f  - > fa)

这可能会更清楚。


What I'd like to achieve is:

apply :: a -> [a -> b] -> [b]

this is kind of the inverse of map:

map :: (a -> b) -> [a] -> [b]

I've tried Hoogle, but to no avail. Can anyone suggest a clean way of doing this in Haskell?

解决方案

apply :: a -> [a -> b] -> [b]
apply a = map ($ a)

which is a pithy way of saying

apply a = map (\f -> f a)

which may be more clear.

这篇关于如何将值应用于函数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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