使用列表实现haskell的Map函数 [英] Map Function using list implementation haskell

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

问题描述

有没有办法使用list实现来编写Haskell map 函数的实现?



我保留出现错误,我认为我没有走上正轨。这是我的:

  map'::(a  - > b) - > [a]  - > [b] 
map'_ [] = []
map'xs ys = [(x,y)| x < - xs | y< - ys]

任何帮助或链接都能指引我走向正确的方向我相信你的意思是理解,而不是实施。我相信你的意思是理解,而不是实施。

无论哪种方式,这都是可行的:

  map'f as = [fa | a<  -  as] 
map'(* 2)[1..5]


Is there a way to write an implementation of the Haskell map function using list implementation?

I keep getting an error and I do not think I am on the right track. This is what I have:

map' :: (a -> b) -> [a] -> [b]
map' _ [] = []
map' xs ys = [ (x, y) | x <- xs | y <- ys ]

Any help or link that will guide me in the right direction would be much appreciated.

解决方案

I believe you mean "comprehension", instead of "implementation".

Either way, this would work:

map' f as = [f a | a <- as]
map' (* 2) [1..5]

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

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